Chapter 6. Network connections
6.1. Creating outgoing connections Copy linkLink copied to clipboard!
To connect to a remote server, pass connection options containing the host and port to the container.connect()
method.
Example: Creating outgoing connections
The default host is localhost
. The default port is 5672.
For information about creating secure connections, Chapter 7, Security.
6.2. Configuring reconnect Copy linkLink copied to clipboard!
Reconnect allows a client to recover from lost connections. It is used to ensure that the components in a distributed system reestablish communication after temporary network or component failures.
Red Hat build of Rhea enables reconnect by default. If a connection attempt fails, the client will try again after a brief delay. The delay increases exponentially for each new attempt, up to a default maximum of 60 seconds.
To disable reconnect, set the reconnect
connection option to false
.
Example: Disabling reconnect
To control the delays between connection attempts, set the initial_reconnect_delay
and max_reconnect_delay
connection options. Delay options are specified in milliseconds.
To limit the number of reconnect attempts, set the reconnect_limit
option.
Example: Configuring reconnect
6.3. Configuring failover Copy linkLink copied to clipboard!
Red Hat build of Rhea allows you to configure alternate connection endpoints programatically.
To specify multiple connection endpoints, define a function that returns new connection options and pass the function in the connection_details
option. The function is called once for each connection attempt.
Example: Configuring failover
This example implements repeating round-robin failover for a list of hosts. You can use this interface to implement your own failover behavior.
6.4. Accepting incoming connections Copy linkLink copied to clipboard!
Red Hat build of Rhea can accept inbound network connections, enabling you to build custom messaging servers.
To start listening for connections, use the container.listen()
method with options containing the local host address and port to listen on.
Example: Accepting incoming connections
The special IP address 0.0.0.0
listens on all available IPv4 interfaces. To listen on all IPv6 interfaces, use [::0]
.
For more information, see the server receive.js example.