News KrakenD CE v2.6 released with OpenTelemetry

Community Documentation

Recent changes

You are viewing a previous version of KrakenD Community Edition (v2.0) , go to the latest version

Gateway integration with RabbitMQ consumers

Document updated on Jan 24, 2022

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 name
  • exchange - 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 - bool true 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 - bool false is recommended to avoid deletions when the consumer is disconnected
  • no_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 as ACK. Defaults to false.
Scarf

Unresolved issues?

The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.

We use cookies to understand how you use our site and to improve your overall experience. By continuing to use our site, you accept our Privacy Policy. More information