此内容没有您所选择的语言版本。
Chapter 2. Getting started
This section shows you how to install AMQ Interconnect on a single host, start the router with the default configuration settings, and distribute messages between two clients.
2.1. Installing AMQ Interconnect 复制链接链接已复制到粘贴板!
AMQ Interconnect 1.5 is distributed as a set of RPM packages, which are available through your Red Hat subscription.
Procedure
Ensure your subscription has been activated and your system is registered.
For more information about using the Customer Portal to activate your Red Hat subscription and register your system for packages, see Appendix B, Using your subscription.
Subscribe to the required repositories:
- Red Hat Enterprise Linux 6
sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-6-server-rpms --enable=amq-clients-2-for-rhel-6-server-rpms
$ sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-6-server-rpms --enable=amq-clients-2-for-rhel-6-server-rpms
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Red Hat Enterprise Linux 7
sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-7-server-rpms --enable=amq-clients-2-for-rhel-7-server-rpms
$ sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-7-server-rpms --enable=amq-clients-2-for-rhel-7-server-rpms
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Red Hat Enterprise Linux 8
sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-8-x86_64-rpms --enable=amq-clients-2-for-rhel-8-x86_64-rpms
$ sudo subscription-manager repos --enable=amq-interconnect-1-for-rhel-8-x86_64-rpms --enable=amq-clients-2-for-rhel-8-x86_64-rpms
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
yum
ordnf
command to install theqpid-dispatch-router
,qpid-dispatch-tools
, andqpid-dispatch-console
packages and their dependencies:sudo yum install qpid-dispatch-router qpid-dispatch-tools qpid-dispatch-console
$ sudo yum install qpid-dispatch-router qpid-dispatch-tools qpid-dispatch-console
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
which
command to verify that theqdrouterd
executable is present.which qdrouterd
$ which qdrouterd /usr/sbin/qdrouterd
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
qdrouterd
executable should be located at/usr/sbin/qdrouterd
.
2.2. Viewing the default router configuration file 复制链接链接已复制到粘贴板!
The router’s configuration file (qdrouterd.conf
) controls the way in which the router functions. The default configuration file contains the minimum number of settings required for the router to run. As you become more familiar with the router, you can add to or change these settings, or create your own configuration files.
By default, the router configuration file defines the following settings for the router:
- Operating mode
- How it listens for incoming connections
- Routing patterns for the message routing mechanism
Procedure
Open the following file:
/etc/qpid-dispatch/qdrouterd.conf
.When AMQ Interconnect is installed,
qdrouterd.conf
is installed in this directory. When the router is started, it runs with the settings defined in this file.Review the default settings in
qdrouterd.conf
.Default Configuration File
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- By default, the router operates in standalone mode. This means that it can only communicate with endpoints that are directly connected to it. It cannot connect to other routers, or participate in a router network.
- 2
- The unique identifier of the router. This ID is used as the
container-id
(container name) at the AMQP protocol level. If it is not specified, the router shall generate a random identifier at startup. - 3
- The
listener
entity handles incoming connections from client endpoints. By default, the router listens on all network interfaces on the default AMQP port (5672). - 4
- By default, the router is configured to use the message routing mechanism. Each
address
entity defines how messages that are received with a particular addressprefix
should be distributed. For example, all messages with addresses that start withclosest
will be distributed using theclosest
distribution pattern.
NoteIf a client requests a message with an address that is not defined in the router’s configuration file, the
balanced
distribution pattern will be used automatically.
Additional resources
- For more information about the router configuration file (including available entities and attributes), see the qdrouterd man page.
2.3. Starting the router 复制链接链接已复制到粘贴板!
After installing AMQ Interconnect, you start the router by using the qdrouterd
command.
Procedure
To start the router, use the
qdrouterd
command.This example uses the default configuration to start the router as a daemon:
qdrouterd -d
$ qdrouterd -d
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The router starts, using the default configuration file stored at
/etc/qpid-dispatch/qdrouterd.conf
.View the log to verify the router status:
qdstat --log
$ qdstat --log
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example shows that the router was correctly installed, is running, and is ready to route traffic between clients:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
- The qdrouterd man page.
2.4. Sending test messages 复制链接链接已复制到粘贴板!
After starting the router, send some test messages to see how the router can connect two endpoints by distributing messages between them.
This procedure demonstrates a simple configuration consisting of a single router with two clients connected to it: a sender and a receiver. The receiver wants to receive messages on a specific address, and the sender sends messages to that address.
A broker is not used in this procedure, so there is no "store and forward" mechanism in the middle. Instead, the messages flow from the sender, through the router, to the receiver only if the receiver is online, and the sender can confirm that the messages have arrived at their destination.
Prerequisites
AMQ Python must be installed. For more information, see Using the AMQ Python Client.
Procedure
Navigate to the AMQ Python examples directory.
cd <install-dir>/examples/python/
$ cd <install-dir>/examples/python/
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - <install-dir>
- The directory where you installed AMQ Python.
Start the
simple_recv.py
receiver client.python simple_recv.py -a 127.0.0.1:5672/examples -m 5
$ python simple_recv.py -a 127.0.0.1:5672/examples -m 5
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command starts the receiver and listens on the
examples
address (127.0.0.1:5672/examples
). The receiver is also set to receive a maximum of five messages.NoteIn practice, the order in which you start senders and receivers does not matter. In both cases, messages will be sent as soon as the receiver comes online.
In a new terminal window, navigate to the Python examples directory and run the
simple_send.py
example:cd <install-dir>/examples/python/ python simple_send.py -a 127.0.0.1:5672/examples -m 5
$ cd <install-dir>/examples/python/ $ python simple_send.py -a 127.0.0.1:5672/examples -m 5
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This command sends five auto-generated messages to the
examples
address (127.0.0.1:5672/examples
) and then confirms that they were delivered and acknowledged by the receiver:all messages confirmed
all messages confirmed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the receiver client received the messages.
The receiver client should display the contents of the five messages:
{u'sequence': 1L} {u'sequence': 2L} {u'sequence': 3L} {u'sequence': 4L} {u'sequence': 5L}
{u'sequence': 1L} {u'sequence': 2L} {u'sequence': 3L} {u'sequence': 4L} {u'sequence': 5L}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.5. Next steps 复制链接链接已复制到粘贴板!
After you successfully install a standalone router and use it to distribute messages between two clients, you can configure a router network topology and route messages.
- Configure a router network topology
- After configuring a single router, you can deploy additional routers and connect them together to form a router network. Router networks can be any arbitrary topology.
- Route messages through the router network
Regardless of the underlying router network topology, you can configure how you want messages to be routed through the router network.
- Configure addresses to specify routing patterns for direct-routed (brokerless) messaging
- Connect the router to a message broker to enable clients to exchange messages with a broker queue.
- Create link routes to define private messaging paths between endpoints.
For more information, see Chapter 5, Routing messages through the router network.