Skip to content

Commit e9f3034

Browse files
committedJun 12, 2023
Improve stream example
1 parent 072ca61 commit e9f3034

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed
 

‎examples/stream_queues/README.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,35 @@ These examples show how to use stream queues with the lib.
66

77
Send a message to a stream queue
88
```
9-
./send_stream.js
9+
node send_stream.js
1010
```
1111

1212
Receive all the messages from stream queue:
1313
```
14-
./receive_stream.js
15-
```
14+
node receive_stream.js
15+
```
16+
17+
Consumers can be configured to receive messages using an offset via the `x-stream-offset` argument. e.g.
18+
19+
```js
20+
channel.consume(queue, onMessage, {
21+
noAck: false,
22+
arguments: {
23+
'x-stream-offset': 'first'
24+
}
25+
});
26+
```
27+
28+
RabbitMQ supports six different types of offset, however specifying them can be
29+
30+
| Offset Type | Example Value | Notes |
31+
|-----------|------------------------------------------------------------------|-------|
32+
| First | `{ 'x-stream-offset': 'first' }` | Start from the first message in the log |
33+
| Last | `{ 'x-stream-offset': 'last' }` | Start from the last "chunk" of messages (could be multiple messages) |
34+
| Next | `{ 'x-stream-offset': 'next' }` | Start from the next message (the default) |
35+
| Offset | `{ 'x-stream-offset': 5 }` | a numerical value specifying an exact offset to attach to the log at |
36+
| Timestamp | `{ 'x-stream-offset': { '!': 'timestamp', value: 1686519750 } }` | a timestamp value specifying the point in time to attach to the log at. The timestamp must be the number of seconds since 00:00:00 UTC, 1970-01-01. Consumers can receive messages published a bit before the specified timestamp. |
37+
| Interval | `{ 'x-stream-offset': '1h' }` | the time interval relative to current time to attach the log at. Valid units are Y, M, D, h, m and s |
38+
39+
40+
See https://www.rabbitmq.com/streams.html#consuming for more details

‎examples/stream_queues/receive_stream.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ const amqp = require('amqplib');
2929
noAck: false,
3030
arguments: {
3131
/*
32-
Here you can specify the offset: : first, last, next, offset and timestamp, i.e.
32+
Here you can specify the offset: : first, last, next, offset, timestamp and interval, i.e.
3333
3434
'x-stream-offset': 'first'
3535
'x-stream-offset': 'last'
3636
'x-stream-offset': 'next'
3737
'x-stream-offset': 5
3838
'x-stream-offset': { '!': 'timestamp', value: 1686519750 }
39+
'x-stream-offset': '1h'
3940
4041
The timestamp must be the desired number of seconds since 00:00:00 UTC, 1970-01-01
42+
The interval units can be Y, M, D, h, m, s
4143
4244
*/
4345
'x-stream-offset': 'first'

0 commit comments

Comments
 (0)
Please sign in to comment.