|
2 | 2 |
|
3 | 3 | Constants representing the standard exchange types are available as: `EXCHANGE_TYPE_DIRECT`, `EXCHANGE_TYPE_FANOUT`, `EXCHANGE_TYPE_TOPIC`, and `EXCHANGE_TYPE_HEADERS`.
|
4 | 4 |
|
5 |
| -Exchanges can be delcared and deleted using the `exchange_declare` and `exchange_delete` APIs. They return a boolean to indicate success (true) or failure (false). |
| 5 | +Exchanges can be delcared and deleted using the `exchange_declare` and `exchange_delete` APIs. They return a boolean to indicate success (`true`) or failure (`false`). |
6 | 6 | Declaring an already existing exchange simply attaches to it, a new exchange is created otherwise.
|
7 | 7 |
|
8 |
| -````julia |
9 |
| - # declare (create if they do not exist) new exchange |
10 |
| - EXCG_DIRECT = "MyDirectExcg" |
11 |
| - EXCG_FANOUT = "MyFanoutExcg" |
12 |
| - success = exchange_declare(chan1, EXCG_DIRECT, EXCHANGE_TYPE_DIRECT) |
13 |
| - success || println("error!") |
14 |
| - success = exchange_declare(chan1, EXCG_FANOUT, EXCHANGE_TYPE_FANOUT) |
15 |
| - success || println("error!") |
| 8 | +```julia |
| 9 | +# declare (create if they do not exist) new exchange |
| 10 | +EXCG_DIRECT = "MyDirectExcg" |
| 11 | +EXCG_FANOUT = "MyFanoutExcg" |
| 12 | +@assert exchange_declare(chan1, EXCG_DIRECT, EXCHANGE_TYPE_DIRECT) |
| 13 | +@assert exchange_declare(chan1, EXCG_FANOUT, EXCHANGE_TYPE_FANOUT) |
16 | 14 |
|
17 |
| - # operate with the exchanges... |
| 15 | +# operate with the exchanges... |
18 | 16 |
|
19 |
| - # delete exchanges |
20 |
| - success = exchange_delete(chan1, EXCG_DIRECT) |
21 |
| - success || println("error!") |
22 |
| - success = exchange_delete(chan1, EXCG_FANOUT) |
23 |
| - success || println("error!") |
24 |
| -```` |
| 17 | +# delete exchanges |
| 18 | +@assert exchange_delete(chan1, EXCG_DIRECT) |
| 19 | +@assert exchange_delete(chan1, EXCG_FANOUT) |
| 20 | +``` |
25 | 21 |
|
26 | 22 | Queues can similarly be declared and deleted.
|
27 | 23 | Attaching to an existing queue also returns the number of pending messages and the number of consumers attached to the queue.
|
28 | 24 |
|
29 |
| -````julia |
| 25 | +```julia |
30 | 26 | QUEUE1 = "MyQueue"
|
31 | 27 | success, queue_name, message_count, consumer_count = queue_declare(chan1, QUEUE1)
|
32 |
| -success || println("error!") |
| 28 | +@assert success |
33 | 29 |
|
34 | 30 | # operate with the queue
|
35 | 31 |
|
36 | 32 | # delete the queue
|
37 | 33 | success, message_count = queue_delete(chan1, QUEUE1)
|
38 |
| -success || println("error!") |
39 |
| -```` |
| 34 | +@assert success |
| 35 | +``` |
40 | 36 |
|
41 | 37 | Messages are routed by binding queues and exchanges to other exchanges. The type of exchange and the routing key configured determine the path.
|
42 | 38 |
|
43 |
| -````julia |
| 39 | +```julia |
44 | 40 | ROUTE1 = "routingkey1"
|
45 | 41 | # bind QUEUE1 to EXCG_DIRECT,
|
46 | 42 | # specifying that only messages with routing key ROUTE1 should be delivered to QUEUE1
|
47 |
| -success = queue_bind(chan1, QUEUE1, EXCG_DIRECT, ROUTE1) |
48 |
| -success || println("error!") |
| 43 | +@assert queue_bind(chan1, QUEUE1, EXCG_DIRECT, ROUTE1) |
49 | 44 |
|
50 | 45 | # operate with the queue
|
51 | 46 |
|
52 | 47 | # remove the binding
|
53 |
| -success = queue_unbind(chan1, QUEUE1, EXCG_DIRECT, ROUTE1) |
54 |
| -success || println("error!") |
55 |
| -```` |
| 48 | +@assert queue_unbind(chan1, QUEUE1, EXCG_DIRECT, ROUTE1) |
| 49 | +``` |
56 | 50 |
|
57 | 51 | Messages on a queue can be purged:
|
58 | 52 |
|
59 |
| -````julia |
| 53 | +```julia |
60 | 54 | success, message_count = queue_purge(chan1, QUEUE1)
|
61 |
| -if success |
62 |
| - println("$message_count messages were purged") |
63 |
| -else |
64 |
| - println("error!") |
65 |
| -end |
66 |
| -```` |
67 |
| - |
| 55 | +@assert success |
| 56 | +@info("messages purged", message_count) |
| 57 | +``` |
0 commit comments