@@ -9,7 +9,32 @@ import (
9
9
"github.com/golang-queue/queue/core"
10
10
)
11
11
12
- // Direct Exchange
12
+ /*
13
+ Example_direct_exchange demonstrates how to use RabbitMQ with a direct exchange.
14
+ This example creates two workers (w1, w2) that both listen to the same queue and exchange,
15
+ and a producer that sends multiple messages to the queue. The workers process the messages
16
+ in a round-robin fashion.
17
+
18
+ Steps:
19
+ 1. Create a mock message to be sent.
20
+ 2. Initialize worker w1 with a direct exchange and queue, and define its processing function.
21
+ 3. Start a queue (q1) with worker w1.
22
+ 4. Initialize worker w2 with the same direct exchange and queue, and define its processing function.
23
+ 5. Start a queue (q2) with worker w2.
24
+ 6. Create a producer worker (w) with the same exchange and routing key.
25
+ 7. Start a queue (q) with the producer worker.
26
+ 8. Send the mock message to the queue multiple times.
27
+ 9. Wait for processing, then release all queues.
28
+
29
+ Expected Output:
30
+ - The two workers alternately print the received message.
31
+
32
+ Unordered Output:
33
+ worker01 get data: foo
34
+ worker02 get data: foo
35
+ worker01 get data: foo
36
+ worker02 get data: foo
37
+ */
13
38
func Example_direct_exchange () {
14
39
m := mockMessage {
15
40
Message : "foo" ,
@@ -92,7 +117,30 @@ func Example_direct_exchange() {
92
117
// worker02 get data: foo
93
118
}
94
119
95
- // Fanout Exchange
120
+ /*
121
+ Example_fanout_exchange demonstrates how to use RabbitMQ with a fanout exchange.
122
+ This example creates two workers (w1, w2) each listening to a different queue bound to the same
123
+ fanout exchange, and a producer that sends a message to the exchange. Both workers receive and
124
+ process the same message.
125
+
126
+ Steps:
127
+ 1. Create a mock message to be sent.
128
+ 2. Initialize worker w1 with a unique queue and the fanout exchange, and define its processing function.
129
+ 3. Start a queue (q1) with worker w1.
130
+ 4. Initialize worker w2 with a different queue and the same fanout exchange, and define its processing function.
131
+ 5. Start a queue (q2) with worker w2.
132
+ 6. Create a producer worker (w) with the same fanout exchange.
133
+ 7. Start a queue (q) with the producer worker.
134
+ 8. Send the mock message to the exchange.
135
+ 9. Wait for processing, then release all queues.
136
+
137
+ Expected Output:
138
+ - Both workers print the received message.
139
+
140
+ Unordered Output:
141
+ worker01 get data: foo
142
+ worker02 get data: foo
143
+ */
96
144
func Example_fanout_exchange () {
97
145
m := mockMessage {
98
146
Message : "foo" ,
0 commit comments