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 nameDescriptionOptional/MandatoryDefault value
#hostnameHostname of the RabbitMQ brokerOptionallocalhost
#portPort number of the RabbitMQ brokerOptional5672
#usernameUsername of the RabbitMQ brokerOptionalguest
#passwordUsername of the RabbitMQ brokerOptionalguest
#maximumConnectionAttempsAmount of retries when connecting to the broker failsOptional3
#timeSlotBetweenConnectionRetriesInMsTime duration between retry attempts determined by using the exponential back off algorithmOptional3000
#enableDebuggingLogsA boolean indicating whether to log debugging eventsOptionalfalse
#extraClientPropertiesA dictionary with keys and values to set the client propertiesOptionalEmpty
#retryA block that can configure the internal Retry instanceOptional[]

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.

publisher publish: 'The message' to: 'the-queue'. 
  • Publish to a routing key through a direct or topic exchange.
publisher publish: 'The message' to: 'a-routing-key' through: 'the-exchange'.
publisher broadcast: 'The message' toAllQueuesBindedTo: 'a-fanout-exchange'.

For proper shutdown and connection closure, you need to run:

publisher stop.