RabbitMQPublisher
March 24, 2026 ยท View on GitHub
This object will connect to an AMQP channel and knows how to publish messages to the specified queue for further processing.
Accepts the following options:
| Attribute name | Description | Optional/Mandatory | Default value |
|---|---|---|---|
| #hostname | Hostname of the RabbitMQ broker | Optional | localhost |
| #port | Port number of the RabbitMQ broker | Optional | 5672 |
| #username | Username of the RabbitMQ broker | Optional | guest |
| #password | Username of the RabbitMQ broker | Optional | guest |
| #maximumConnectionAttemps | Amount of retries when connecting to the broker fails | Optional | 3 |
| #timeSlotBetweenConnectionRetriesInMs | Time duration between retry attempts determined by using the exponential back off algorithm | Optional | 3000 |
| #enableDebuggingLogs | A boolean indicating whether to log debugging events | Optional | false |
| #extraClientProperties | A dictionary with keys and values to set the client properties | Optional | Empty |
| #retry | A block that can configure the internal Retry instance | Optional | [] |
Usage
You need to instantiate the publisher with the options above and then send #start to ensure the channel is open.
| publisher |
publisher := RabbitMQPublisher configuredBy: [ :options |
options
at: #username put: 'guest';
at: #password put: 'guest';
at: #hostname put: 'localhost'
].
publisher start.
Once the publisher is started, you can use its protocol to send messages.
- Publish directly to a specific queue using the default exchange.
publisher publish: 'The message' to: 'the-queue'.
publisher publish: 'The message' to: 'a-routing-key' through: 'the-exchange'.
- Publish to all queues bound to a fan out exchange.
publisher broadcast: 'The message' toAllQueuesBindedTo: 'a-fanout-exchange'.
For proper shutdown and connection closure, you need to run:
publisher stop.