Skip to content

Commit b9833b1

Browse files
authored
Merge pull request #44 from ba-st/fanout-binding
Enhance RabbitMQ clients to support Fanout Exchanges
2 parents 28fe5ab + 5668c02 commit b9833b1

File tree

8 files changed

+395
-61
lines changed

8 files changed

+395
-61
lines changed

docs/tutorials/RabbitMQPublisher.md

+42
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,45 @@ Accepts the following options:
1717
| #enableDebuggingLogs | A boolean indicating whether to log debugging events | Optional | false |
1818
| #extraClientProperties | A dictionary with keys and values to set the [client properties](https://www.rabbitmq.com/docs/connections#capabilities) |Optional | Empty |
1919
| #retry | A block that can configure the internal `Retry` instance | Optional | `[]` |
20+
21+
## Usage
22+
23+
You need to instantiate the publisher with the options above and then send `#start` to ensure the [channel](https://www.rabbitmq.com/docs/channels) is open.
24+
25+
```smalltalk
26+
| publisher |
27+
publisher := RabbitMQPublisher configuredBy: [ :options |
28+
options
29+
at: #username put: 'guest';
30+
at: #password put: 'guest';
31+
at: #hostname put: 'localhost'
32+
].
33+
34+
publisher start.
35+
```
36+
37+
Once the publisher is started, you can use its protocol to send messages.
38+
39+
* Publish directly to a specific queue using the [default exchange](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-default).
40+
41+
```smalltalk
42+
publisher publish: 'The message' to: 'the-queue'.
43+
```
44+
45+
* Publish to a routing key through a [direct](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-direct) or [topic](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-topic) exchange.
46+
47+
```smalltalk
48+
publisher publish: 'The message' to: 'a-routing-key' through: 'the-exchange'.
49+
```
50+
51+
* Publish to all queues bound to a [fanout exchange](https://www.rabbitmq.com/tutorials/amqp-concepts#exchange-fanout).
52+
53+
```smalltalk
54+
publisher broadcast: 'The message' toAllQueuesBindedTo: 'a-fanout-exchange'.
55+
```
56+
57+
For proper shutdown and connection closure, you need to run:
58+
59+
```smalltalk
60+
publisher stop.
61+
```

docs/tutorials/RabbitMQWorker.md

+35
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,38 @@ Accepts the following options:
1919
| #retry | A block that can configure the internal `Retry` instance | Optional | `[]` |
2020
| #queueName | Queue name where to consume from | Mandatory | |
2121
| #queueDurable | When false sets the [queue durability](https://www.rabbitmq.com/docs/queues#durability) to transient, otherwise will be durable | Optional | true |
22+
23+
## Usage
24+
25+
You need to instantiate the worker with the options above.
26+
27+
```smalltalk
28+
| worker |
29+
worker := RabbitMQWorker configuredBy: [ :options |
30+
options
31+
at: #hostname put: 'localhost';
32+
at: #queueName put: aQueueName;
33+
at: #extraClientProperties put: (
34+
Dictionary new
35+
at: 'process' put: 'aName';
36+
yourself )
37+
]
38+
processingPayloadWith: [:message | message inspect ].
39+
```
40+
41+
Before sending `#start`, you need to consider [bind the queue](https://www.rabbitmq.com/tutorials/tutorial-four-python#bindings) to an exchange if necessary.
42+
43+
```smalltalk
44+
worker bindQueueTo: 'an-exchange-name' routedBy: 'a-routing-key'.
45+
```
46+
47+
The #start method will block the socket, waiting for any new event, so it's recommended to fork the process and ensure that, before terminating, you unbind the queue and close the connection properly.
48+
49+
```smalltalk
50+
workerProcess := [
51+
[ worker start ] ensure: [
52+
worker unbindQueueTo: 'an-exchange-name' routedBy: 'a-routing-key'.
53+
worker stop
54+
]
55+
] fork
56+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Extension { #name : 'RabbitMQPublisher' }
2+
3+
{ #category : '*Ansible-Deprecated-v3' }
4+
RabbitMQPublisher >> publish: aMessageCollection onQueueNamed: aQueueName [
5+
6+
self
7+
deprecated: 'Use confirmPublicationWith:otherwise:'
8+
transformWith:
9+
'`@receiver publish: `@aMessageCollection onQueueNamed: `@aQueueName'
10+
-> '`@receiver publishAll: `@aMessageCollection to: `@aQueueName'.
11+
12+
self publishAll: aMessageCollection to: aQueueName
13+
]
14+
15+
{ #category : '*Ansible-Deprecated-v3' }
16+
RabbitMQPublisher >> publishOnly: aMessage onQueueNamed: aQueueName [
17+
18+
self
19+
deprecated: 'Use confirmPublicationWith:otherwise:'
20+
transformWith:
21+
'`@receiver publishOnly: `@aMessage onQueueNamed: `@aQueueName'
22+
-> '`@receiver publish: `@aMessage to: `@aQueueName'.
23+
24+
self publish: aMessage to: aQueueName
25+
]

0 commit comments

Comments
 (0)