|
1 |
| -Single active consumer |
| 1 | +Super stream example |
2 | 2 | ---
|
3 | 3 |
|
4 |
| -This is an example to enable single active consumer functionality for superstream: |
5 |
| -https://www.rabbitmq.com/blog/2022/07/05/rabbitmq-3-11-feature-preview-single-active-consumer-for-streams |
6 |
| -https://www.rabbitmq.com/blog/2022/07/13/rabbitmq-3-11-feature-preview-super-streams |
| 4 | +[Super Streams Documentation](https://www.rabbitmq.com/streams.html#super-streams) for more details. |
| 5 | +[Super Streams blog post](https://blog.rabbitmq.com/posts/2022/07/rabbitmq-3-11-feature-preview-super-streams) |
7 | 6 |
|
8 |
| -This folder contains a consumer and a super-stream consumer configured to enable it. |
9 |
| -You can use the example in the super-stream folder to produce messages for a super-stream. |
10 | 7 |
|
11 |
| -You can then run the single_active_consumer_super_stream.rs in this folder. |
12 |
| -Assuming the super-stream is composed by three streams, you can see that the Consumer will consume messages from all the streams part of the superstream. |
| 8 | +This example shows how to use the Super Stream feature in RabbitMQ 3.11.0. |
13 | 9 |
|
14 |
| -You can then run another consumer in parallel. |
15 |
| -now you'll see that one of the two consumers will consume from 2 streams while the other on one stream. |
| 10 | +Then run the producer in one terminal: |
16 | 11 |
|
17 |
| -If you run another you'll see that every Consumer will read from a single stream. |
| 12 | + $ cargo run --release -- --producer |
18 | 13 |
|
19 |
| -If you then stop one of the Consumer you'll notice that the related stream is now read from on the Consumer which is still running. |
| 14 | + |
| 15 | +And the consumer in another terminal: |
| 16 | + |
| 17 | + $ cargo run --release -- --consumer |
| 18 | + |
| 19 | +You should see the consumer receiving the messages from the producer. |
| 20 | + |
| 21 | +It would be something like: |
| 22 | +```bash |
| 23 | +$ cargo run -- --producer |
| 24 | +Starting SuperStream Producer |
| 25 | +Super Stream Producer connected to RabbitMQ |
| 26 | +Super Stream Producer sent 0 messages to invoices |
| 27 | +Super Stream Producer sent 1 messages to invoices |
| 28 | +Super Stream Producer sent 2 messages to invoices |
| 29 | +Super Stream Producer sent 3 messages to invoices |
| 30 | +``` |
| 31 | + |
| 32 | +```bash |
| 33 | +$ cargo run --release -- --consumer my_first_consumer |
| 34 | +Starting SuperStream Consumer my_first_consumer |
| 35 | +Super Stream Consumer connected to RabbitMQ. ConsumerName my_first_consumer |
| 36 | +Consumer Name my_first_consumer: Got message: super_stream_message_1 from stream: invoices-1 with offset: 33 |
| 37 | +Consumer Name my_first_consumer: Got message: super_stream_message_2 from stream: invoices-2 with offset: 34 |
| 38 | +Consumer Name my_first_consumer: Got message: super_stream_message_3 from stream: invoices-0 with offset: 37 |
| 39 | +Consumer Name my_first_consumer: Got message: super_stream_message_4 from stream: invoices-0 with offset: 36 |
| 40 | +Consumer Name my_first_consumer: Got message: super_stream_message_5 from stream: invoices-1 with offset: 39 |
| 41 | +Consumer Name my_first_consumer: Got message: super_stream_message_6 from stream: invoices-2 with offset: 40 |
| 42 | +Consumer Name my_first_consumer: Got message: super_stream_message_7 from stream: invoices-0 with offset: 41 |
| 43 | +Consumer Name my_first_consumer: Got message: super_stream_message_8 from stream: invoices-1 with offset: 42 |
| 44 | +Consumer Name my_first_consumer: Got message: super_stream_message_9 from stream: invoices-2 with offset: 43 |
| 45 | +Consumer Name my_first_consumer: Got message: super_stream_message_10 from stream: invoices-1 with offset: 44 |
| 46 | +``` |
| 47 | + |
| 48 | +To see the Single active consumer in action, run another consumer: |
| 49 | + |
| 50 | + $ cargo run --release -- --consumer my_second_consumer |
| 51 | + |
| 52 | +You should see the second consumer receiving the part of the messages from the producer. In thi case only the messages coming from the `invoices-1`. |
| 53 | + |
| 54 | +It should be something like: |
| 55 | +```bash |
| 56 | +$ cargo run --release -- --consumer my_second_consumer |
| 57 | +Starting SuperStream Consumer my_second_consumer |
| 58 | +Super Stream Consumer connected to RabbitMQ. ConsumerName my_second_consumer |
| 59 | +Consumer Name my_second_consumer: Got message: super_stream_message_64 from stream: invoices-1 with offset: 86 |
| 60 | +Consumer Name my_second_consumer: Got message: super_stream_message_65 from stream: invoices-1 with offset: 87 |
| 61 | +Consumer Name my_second_consumer: Got message: super_stream_message_66 from stream: invoices-1 with offset: 88 |
| 62 | +Consumer Name my_second_consumer: Got message: super_stream_message_67 from stream: invoices-1 with offset: 89 |
| 63 | +Consumer Name my_second_consumer: Got message: super_stream_message_68 from stream: invoices-1 with offset: 90 |
| 64 | +Consumer Name my_second_consumer: Got message: super_stream_message_69 from stream: invoices-1 with offset: 90 |
| 65 | +Consumer Name my_second_consumer: Got message: super_stream_message_70 from stream: invoices-1 with offset: 90 |
| 66 | +``` |
| 67 | +and the first consumer should be receiving the rest of the messages: |
| 68 | +```bash |
| 69 | +Consumer Name my_first_consumer: Got message: super_stream_message_88 from stream: invoices-0 with offset: 92 |
| 70 | +Consumer Name my_first_consumer: Got message: super_stream_message_87 from stream: invoices-2 with offset: 93 |
| 71 | +Consumer Name my_first_consumer: Got message: super_stream_message_89 from stream: invoices-2 with offset: 95 |
| 72 | +Consumer Name my_first_consumer: Got message: super_stream_message_90 from stream: invoices-0 with offset: 97 |
| 73 | +Consumer Name my_first_consumer: Got message: super_stream_message_91 from stream: invoices-0 with offset: 96 |
| 74 | +Consumer Name my_first_consumer: Got message: super_stream_message_92 from stream: invoices-2 with offset: 99 |
| 75 | +Consumer Name my_first_consumer: Got message: super_stream_message_93 from stream: invoices-2 with offset: 101 |
| 76 | +``` |
20 | 77 |
|
21 | 78 |
|
22 | 79 |
|
|
0 commit comments