AMQP connection management
To consume messages from the AMQP server, clients must establish a connection with the server. This connection can either be reused by multiple clients or a separate connection can be created for each client. Since establishing AMQP connections is resource-intensive, it is generally recommended to reuse connections rather than creating a new one for every client. However, using the same connection instance for multiple clients may couple them and interfere with resource allocation. The choice of approach should depend on the available resources and business requirements to determine the most suitable option for the adapter.
Each source service in the application is treated as a client of the AMQP server. A connection instance is assigned to each service, which can either be unique to the service or shared with other services.
If the amqpServerConnection
configuration parameter is specified in the service
configuration, a unique connection instance is created and assigned to that service.
{
"serviceName": "simpleQueueListener",
"serviceType": "QUEUE_LISTENER",
"description": "Listens to queue updates",
"config": {
"application": {
"amqpServerConnection": {
"connectionUrl": "amqp://localhost:5672"
},
"sourceName": "testQueue",
"diffusionTopicTemplate": "target/testQueue"
}
}
}
However, if a sharedConfig of type AMQP_SERVER is specified in the adapter configuration and is referred to in the service configuration, all services that reference this shared configuration will share the same connection instance.
{
"sharedConfigs": [
{
"sharedConfigName": "rabbitMqBroker",
"sharedConfigType": "AMQP_SERVER",
"description": "Local rabbit mq connection details",
"config": {
"application": {
"amqpServerConnection": {
"connectionUrl": "amqp://localhost:5672"
}
}
}
}
],
"services": [
{
"serviceName": "simpleTopicListener",
"serviceType": "TOPIC_LISTENER",
"description": "Listens to a topic updates",
"config": {
"sharedConfigName": "rabbitMqBroker",
"application": {
"sourceName": "test_topic",
"diffusionTopicTemplate": "target/test_topic"
}
}
},
{
"serviceName": "simpleQueueListener",
"serviceType": "QUEUE_LISTENER",
"description": "Listens to queue updates",
"config": {
"sharedConfigName": "rabbitMqBroker",
"application": {
"sourceName": "test_queue",
"diffusionTopicTemplate": "target/test_queue"
}
}
}
]
}
A service can either refer to a shared configuration or specify the AMQP connection details in its own configuration, but not both. If both are specified, a configuration validation error is thrown when the service is added. |
AMQP connection retries
If the adapter fails to establish an AMQP connection during instantiation or if the
connection gets disconnected, while the adapter is running, it will reattempt to
establish the connection. The configuration parameters for the amqpServerConnection
can be adjusted to modify the connection retry behavior.
If a service fails to establish an AMQP connection, the service will be paused and will automatically resume once the connection is successfully established.