Cameleer

RabbitMQ component

The rabbitmq component sends and consumes RabbitMQ messages over AMQP 0-9-1 with the options of Apache Camel's older camel-rabbitmq component.

Scheme: rabbitmq: · Crate: cameleer-amqp · Cargo feature: amqp · Consumer: yes · Producer: yes · Apache Camel: RabbitMQ (Camel 3)

When to use it

  • Run routes written for Camel 2 or 3 rabbitmq: endpoints without rewriting them.
  • Consume a RabbitMQ queue with manual acknowledgement (autoAck=false).
  • Publish to an exchange with a routing key, publisher confirms or guaranteed delivery.

Apache Camel 4 replaced this component with spring-rabbitmq; Cameleer keeps both.

URI format

text
rabbitmq:exchangeName[?options]
rabbitmq://host:port/exchangeName[?options]     (Camel 2 style)

Example

yaml example: rabbitmq-orders-queue
- route:
    id: eu-orders
    from:
      uri: rabbitmq:orders
      parameters:
        hostname: "{{env:RABBITMQ_HOST:localhost}}"
        portNumber: "{{env:RABBITMQ_PORT:5672}}"
        username: "{{env:RABBITMQ_USER:guest}}"
        password: "{{env:RABBITMQ_PASSWORD:guest}}"
        queue: eu-orders
        routingKey: eu
        autoAck: false
        autoDelete: false
      steps:
        - log: "EU order: ${body}"
        - to: log:orders

The route declares the direct exchange orders and the queue eu-orders bound with key eu, and acknowledges each message after the route has processed it.

Rust DSL

rust
use cameleer_core::prelude::*;

pub fn routes(ctx: &CamelContext) -> Result<()> {
    ctx.add_routes(|b| {
        b.from("rabbitmq:orders?hostname=localhost&portNumber=5672&queue=eu-orders&routingKey=eu&autoAck=false&autoDelete=false")
            .route_id("eu-orders")
            .log("EU order: ${body}")
            .to("log:orders");
    })
}

Options

optiondefaultdescription
hostname, portNumberlocalhost, 5672Broker address.
addresseshost:port list; takes precedence over hostname and port.
username, password, vhostguest, guest, /Credentials and virtual host.
queueQueue to consume (comma separated for several).
routingKeyBinding key / routing key.
exchangeTypedirectdirect, fanout, topic or headers.
declaretrueDeclare the exchange, queue and binding.
durabletrueDurable exchange and queue.
autoDeletetrueAuto-delete exchange and queue.
exclusive, exclusiveConsumerfalseExclusive queue / consumer.
autoAcktrueBroker auto-ack. false: ack after success, reject on failure (requeued only when the exchange has header CamelRabbitmqRequeue=true).
concurrentConsumers1Consumer channels.
prefetchEnabled, prefetchCount, prefetchGlobalfalse, 0, falsebasic.qos settings.
deadLetterExchange, deadLetterQueue, deadLetterRoutingKey, deadLetterExchangeTypeDead letter topology.
requestTimeout20000InOut producer: wait (ms) for the reply.
publisherAcknowledgementsfalseWait for publisher confirms.
publisherAcknowledgementsTimeout5000ms to wait for a confirm.
mandatoryfalsePublish with the mandatory flag.
guaranteedDeliveriesfalseConfirms plus mandatory.
bridgeEndpointfalseIgnore the CamelRabbitmqRoutingKey / CamelRabbitmqExchangeName headers of incoming messages.
skipQueueDeclare, skipQueueBind, skipExchangeDeclarefalseSkip parts of the declaration.
arg.queue.*, arg.exchange.*, arg.binding.*Declaration arguments.
requestedHeartbeat60Heartbeat in seconds.
sslProtocoltrue, TLS, TLSv1.2 or TLSv1.3 enables TLS (amqps).
sslContextParameters, useGlobalSslContextParametersTLS trust settings.

Message headers

headerdirectiondescription
CamelRabbitmqRoutingKeyin/outRouting key (producer override unless bridgeEndpoint).
CamelRabbitmqExchangeNamein/outExchange (producer override unless bridgeEndpoint).
CamelRabbitmqExchangeOverrideNameinProducer: exchange for this message.
CamelRabbitmqDeliveryTag, CamelRabbitmqRedeliveryTagoutConsumer delivery information.
CamelRabbitmqRequeueinWith autoAck=false: requeue a failed message.
CamelRabbitmqRequestTimeoutinProducer: reply timeout for this message.
CamelRabbitmqContentType, CamelRabbitmqCorrelationId, CamelRabbitmqMessageId, CamelRabbitmqPriority, CamelRabbitmqDeliveryMode, CamelRabbitmqExpiration, CamelRabbitmqTimestamp, CamelRabbitmqType, CamelRabbitmqUserId, CamelRabbitmqAppId, CamelRabbitmqReplyToin/outAMQP message properties.

Run it with Docker

sh
docker run --rm -e RABBITMQ_HOST=rabbitmq -v "$PWD:/routes:ro" pmsudhi/cameleer run /routes/orders.camel.yaml

Common questions

Why does my queue disappear when the route stops?

autoDelete defaults to true in this component, as in Camel's. Set autoDelete=false for a lasting queue.

How do I requeue a message that failed?

With autoAck=false, set the header CamelRabbitmqRequeue to true in the error handling; otherwise a failed message is rejected without requeue.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub