Document updated on Jan 24, 2022
Gateway integration with RabbitMQ consumers
The AMQP component allows to send and receive messages to and from a queue through the API Gateway.
The configuration of the queue is a straightforward process. To connect the endpoints to the messaging system you only need to include the extra_config
key with the namespaces backend/amqp/consumer
or backend/amqp/producer
.
To create Async agents that consume messages asynchronously and without requiring a user request, see Async Agents.
The parameters of this integration follow the AMQP specification. To understand what are the implications of a certain parameter, see the AMQP Complete Reference Guide.
KrakenD creates both the exchange and the queue for you.
Configuration
The consumer retrieves messages from the queue when a KrakenD endpoint plugs to its AMQP backend. The recommendation is to connect consumers to GET
endpoints.
A single endpoint can consume messages from N queues, or can consume N messages from the same queue by adding N backends with the proper queue name.
See Async Agents to consume messages without an endpoint.
The needed configuration to run a consumer is:
{
"backend": [{
"host": ["amqp://guest:[email protected]:5672"],
"disable_host_sanitize": true,
"extra_config": {
"backend/amqp/consumer": {
"name": "queue-1",
"exchange": "some-exchange",
"durable": true,
"delete": false,
"no_wait": true,
"no_local": false,
"routing_key": ["#"],
"prefetch_count": 10,
"prefetch_size": 1024,
"auto_ack": false
}
}
}]
}
name
- string as the queue nameexchange
- string the exchange name (must have a topic type if already exists).routing_key
- list: The list of routing keys you will use to consume messages.durable
- booltrue
is recommended, but depends on the use case. Durable queues will survive server restarts and remain when there are no remaining consumers or bindings.delete
- boolfalse
is recommended to avoid deletions when the consumer is disconnectedno_wait
- bool: When true, do not wait for the server to confirm the request and immediately begin deliveries. If it is not possible to consume, a channel exception will be raised and the channel will be closed.prefetch_count
- int (optional): Is the number of messages you want to prefetch prior to consume them.prefetch_size
- int (optional): Is the number of bytes you want to use to prefetch messages.no_local
- bool (optional) - The no_local flag is not supported by RabbitMQ.auto_ack
- bool. When KrakenD retrieves the messages, regardless of the success or failure of the operation, it marks them asACK
. Defaults tofalse
.