Document updated on Jan 24, 2022
Gateway integration with RabbitMQ producers
The AMQP producer component allows to send messages to 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 namespace backend/amqp/producer
.
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.
Producer Configuration
{
"backend": [{
"host": ["amqp://guest:[email protected]:5672"],
"disable_host_sanitize": true,
"extra_config": {
"backend/amqp/producer": {
"name": "queue-1",
"exchange": "some-exchange",
"durable": true,
"delete": false,
"no_wait": true,
"no_local": false,
"routing_key": "#",
"prefetch_count": 10,
"prefetch_size": 1024,
"mandatory": false,
"immediate": false
}
}
}]
}
name
- string as the queue nameexchange
- string the exchange name (must have a topic type if already exists).routing_key
- string: The routing keys you will use to send 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 producer 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.mandatory
- bool (optional): The exchange must have at least one queue bound when true. Defaults tofalse
.immediate
- bool (optional): A consumer must be connected to the queue when true. Defaults tofalse
.
Additionally, the items below are parameter keys that can be present in the endpoint URL and are passed to the producer. Parameters need capitalization on the first letter.
exp_key
- stringreply_to_key
- stringmsg_id_key
- stringpriority_key
- string - Key of the request parameters that is used as the priority value for the produced message.routing_key
- string - Key of the request parameters that is used as the routing value for the produced message.
{route}
, define it in the config as Route
.For instance, an endpoint
URL could be declared as /produce/{a}/{b}/{id}/{prio}/{route}
and the producer knows how to map them with a configuration like this:
{
...
"exp_key":"A",
"reply_to_key":"B",
"msg_id_key":"Id",
"priority_key":"Prio",
"routing_key":"Route"
}