Este conteúdo não está disponível no idioma selecionado.
Chapter 6. Network connections
6.1. Connection URLs Copiar o linkLink copiado para a área de transferência!
Connection URLs encode the information used to establish new connections.
Connection URL syntax
scheme://host[:port]
scheme://host[:port]
-
Scheme - The connection transport, either
amqpfor unencrypted TCP oramqpsfor TCP with SSL/TLS encryption. - Host - The remote network host. The value can be a hostname or a numeric IP address. IPv6 addresses must be enclosed in square brackets.
-
Port - The remote network port. This value is optional. The default value is 5672 for the
amqpscheme and 5671 for theamqpsscheme.
Connection URL examples
amqps://example.com amqps://example.net:56720 amqp://127.0.0.1 amqp://[::1]:2000
amqps://example.com
amqps://example.net:56720
amqp://127.0.0.1
amqp://[::1]:2000
6.2. Creating outgoing connections Copiar o linkLink copiado para a área de transferência!
To connect to a remote server, call the container::connect() method with a connection URL. This is typically done inside the messaging_handler::on_container_start() method.
Example: Creating outgoing connections
For information about creating secure connections, see Chapter 7, Security.
6.3. Configuring reconnect Copiar o linkLink copiado para a área de transferência!
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.
AMQ C++ disables reconnect by default. To enable it, set the reconnect connection option to an instance of the reconnect_options class.
Example: Enabling reconnect
With reconnect enabled, if a connection is lost or a connection attempt fails, the client will try again after a brief delay. The delay increases exponentially for each new attempt.
To control the delays between connection attempts, set the delay, delay_multiplier, and max_delay options. All durations are specified in milliseconds.
To limit the number of reconnect attempts, set the max_attempts option. Setting it to 0 removes any limit.
Example: Configuring reconnect
6.4. Configuring failover Copiar o linkLink copiado para a área de transferência!
AMQ C++ allows you to configure multiple connection endpoints. If connecting to one fails, the client attempts to connect to the next in the list. If the list is exhausted, the process starts over.
To specify alternate connection endpoints, set the failover_urls reconnect option to a list of connection URLs.
Example: Configuring failover
6.5. Accepting incoming connections Copiar o linkLink copiado para a área de transferência!
AMQ C++ can accept inbound network connections, enabling you to build custom messaging servers.
To start listening for connections, use the proton::container::listen() method with a URL 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.cpp example.