RabbitMQ
Warning
The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described .
Spec metadata fields
To configure communication using TLS, ensure that the RabbitMQ nodes have TLS enabled and provide the caCert
, clientCert
, clientKey
metadata in the component configuration. For example:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: rabbitmq-pubsub
spec:
type: pubsub.rabbitmq
version: v1
metadata:
- name: host
value: "amqps://localhost:5671"
- name: consumerID
value: myapp
value: false
- name: deletedWhenUnused
value: false
- name: autoAck
value: false
- name: deliveryMode
value: 0
- name: requeueInFailure
value: false
- name: prefetchCount
value: 0
- name: reconnectWait
value: 0
- name: concurrencyMode
value: parallel
- name: publisherConfirm
value: false
- name: enableDeadLetter # Optional enable dead Letter or not
value: true
- name: maxLen # Optional max message count in a queue
value: 10485760
- name: exchangeKind
value: fanout
- name: caCert
value: ${{ myLoadedCACert }}
- name: clientCert
value: ${{ myLoadedClientCert }}
- name: clientKey
secretKeyRef:
name: myRabbitMQClientKey
key: myRabbitMQClientKey
Note that while the caCert
and clientCert
values may not be secrets, they can be referenced from a Dapr secret store as well for convenience.
The RabbitMQ pub/sub component has no built-in support for retry strategies. This means that the sidecar sends a message to the service only once. When the service returns a result, the message will be marked as consumed regardless of whether it was processed correctly or not. Note that this is common among all Dapr PubSub components and not just RabbitMQ. Dapr can try redelivering a message a second time, when autoAck
is set to false
and requeueInFailure
is set to true
.
To make Dapr use more sophisticated retry policies, you can apply a to the RabbitMQ pub/sub component.
- When using
autoAck = false
andrequeueInFailure = true
, RabbitMQ is the one responsible for re-delivering messages and any subscriber can get the redelivered message. If you have more than one instance of your consumer, then it’s possible that another consumer will get it. This is usually the better approach because if there’s a transient failure, it’s more likely that a different worker will be in a better position to successfully process the message. - Using Resiliency makes the same Dapr sidecar retry redelivering the messages. So it will be the same Dapr sidecar and the same app receiving the same message.
Create a RabbitMQ server
You can run a RabbitMQ server locally using Docker:
You can then interact with the server using the client port: localhost:5672
.
The easiest way to install RabbitMQ on Kubernetes is by using the :
helm install rabbitmq stable/rabbitmq
Look at the chart output and get the username and password.
This will install RabbitMQ into the default
namespace. To interact with RabbitMQ, find the service with: kubectl get svc rabbitmq
.
rabbitmq.default.svc.cluster.local:5672
Setting exchangeKind
to "topic"
uses the topic exchanges, which are commonly used for the multicast routing of messages. Messages with a routing key
will be routed to one or many queues based on the routing key
defined in the metadata when subscribing. The routing key is defined by the routingKey
metadata. For example, if an app is configured with a routing key keyA
:
It will receive messages with routing key keyA
, and messages with other routing keys are not received.
// publish messages with routing key `keyA`, and these will be received by the above example.
client.PublishEvent(context.Background(), "pubsub", "B", []byte("this is a message"), dapr.PublishEventWithMetadata(map[string]string{"routingKey": "keyA"}))
// publish messages with routing key `keyB`, and these will not be received by the above example.
client.PublishEvent(context.Background(), "pubsub", "B", []byte("this is another message"), dapr.PublishEventWithMetadata(map[string]string{"routingKey": "keyB"}))
Bind multiple routingKey
Multiple routing keys can be separated by commas.
The example below binds three routingKey
: keyA
, keyB
, and ""
. Note the binding method of empty keys.
For more information see rabbitmq exchanges.
Related links
- Basic schema for a Dapr component in the Related links section