You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to make sure that a given message isn't sent more than once, you must use deduplication.
129
+
To create a publisher with deduplication, you just need to pass `publisherRef` to the `declarePublisher` function, this way RabbitMQ will detect messages with lower ids and discard them.
130
+
Note that these ids are incremental, so you have to be careful about how your application publishes the messages, as the order cannot be guaranteed in multi-threaded applications.
131
+
Note: The server does not control the publisherRef across the producers. It's the user's responsibility to guarantee that.
132
+
133
+
You can publish messages either defining a `publishingId` or not:
134
+
In the first case you call the `send` function with `publishingId` defined inside the `MessageOptions`. It's the users responsability to guarantee a valid `publishingId`.
135
+
In the latter case you just call `send` and the publisher will use the next valid `publishingId`.
awaitdeduplicationPublisher.send(Buffer.from("my message content"), { publishingId: 5n }) //here we are passing 5 as publishingId, the message will be sent only if the last publishingId was lower
152
+
awaitdeduplicationPublisher.send(Buffer.from("my message content")) //here we are not passing any publishingId, the publisher will use the next valid publishingId
By default the client uses the `creditsOnChunkCompleted(1, 1)` policy. This policy grants that messages will be processed in order, as a new chunk will only be requested once the current chunk has been processed. It is possible to override this policy by passing `creditPolicy` to the consumer options. Be aware that modifying this policy can lead to out-of-order message processing.
//with the second publisher if we try to send messages with lower publishingId than the last one, they will not be stored
44
+
awaitsecondDeduplicationPublisher.send(Buffer.from("Test message 5"),{publishingId: 1n})//won't be stored
45
+
awaitsecondDeduplicationPublisher.send(Buffer.from("Test message 6"),{publishingId: 2n})//won't be stored
46
+
awaitsecondDeduplicationPublisher.send(Buffer.from("Test message 7"),{publishingId: 7n})//this will be stored since 7 is greater than 3, the last highest publishingId
0 commit comments