-
Notifications
You must be signed in to change notification settings - Fork 11
230 change stream options when already created #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e1243b3
removed boot param
dc1992 5c51fc0
removed boot from tests
dc1992 8379808
conditionally activate deduplication in tests
dc1992 4983d86
activate deduplication for deduplication tests
dc1992 778eba4
race condition
dc1992 ffb0ca8
rollback race condition
dc1992 7d07c29
fix test
dc1992 3b25ea0
readme
dc1992 b6588bb
fix send concurrency
dc1992 5e21307
added example
dc1992 cfb1ce0
new deduplication implementation
dc1992 c4c8bc2
added tests
dc1992 7f89341
more tests
dc1992 90e5457
example
dc1992 15dc77a
typo
dc1992 e809078
readme
dc1992 68abb5a
renamed variable
dc1992 dda0766
replaced sent with stored
dc1992 600f605
updated readme
dc1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| Run this example only with rabbit management version >= 3.13.0. | ||
| */ | ||
|
|
||
| const rabbit = require("rabbitmq-stream-js-client") | ||
| const { randomUUID } = require("crypto") | ||
|
|
||
| const rabbitUser = process.env.RABBITMQ_USER || "rabbit" | ||
| const rabbitPassword = process.env.RABBITMQ_PASSWORD || "rabbit" | ||
|
|
||
| async function main() { | ||
| const streamName = `example-${randomUUID()}` | ||
| const publisherRef = `publisher-${randomUUID()}` | ||
| console.log(`Creating stream ${streamName}`) | ||
|
|
||
| const client = await rabbit.connect({ | ||
| hostname: "localhost", | ||
| port: 5552, | ||
| username: rabbitUser, | ||
| password: rabbitPassword, | ||
| vhost: "/", | ||
| heartbeat: 0, | ||
| }) | ||
| await client.createStream({ stream: streamName }) | ||
|
|
||
| //to declare a publisher with deduplication enabled, you need to set a publisherRef | ||
| const firstDeduplicationPublisher = await client.declarePublisher({ stream: streamName, publisherRef: publisherRef }) | ||
|
|
||
| //with deduplication actived, you can send messages without a publishingId; in this case it will be incremental | ||
| await firstDeduplicationPublisher.send(Buffer.from("Test message 1")) //publishingId = 1 | ||
| await firstDeduplicationPublisher.send(Buffer.from("Test message 2")) //publishingId = 2 | ||
| //but you can also set a publishingId, note that it must be greater than the last one for the message to be sent | ||
| await firstDeduplicationPublisher.send(Buffer.from("Test message 3"), { publishingId: 3n }) //publishingId = 3 | ||
| //if you choose a publishingId that is less than the last one, the message will not be sent | ||
| await firstDeduplicationPublisher.send(Buffer.from("Test message 4"), { publishingId: 1n }) //this message won't be sent | ||
dc1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await firstDeduplicationPublisher.flush() | ||
| const firstPublisherPublishingId = await firstDeduplicationPublisher.getLastPublishingId() | ||
| await firstDeduplicationPublisher.close() | ||
|
|
||
| console.log(`Publishing id is ${firstPublisherPublishingId} (must be 3)`) //this must be the greatest publishingId sent, 3 in this case | ||
|
|
||
| const secondDeduplicationPublisher = await client.declarePublisher({ stream: streamName, publisherRef: publisherRef }) | ||
| //with the second publisher if we try to send messages with lower publishingId than the last one, they will not be sent | ||
| await secondDeduplicationPublisher.send(Buffer.from("Test message 5"), { publishingId: 1n }) //won't be sent | ||
dc1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await secondDeduplicationPublisher.send(Buffer.from("Test message 6"), { publishingId: 2n }) //won't be sent | ||
| await secondDeduplicationPublisher.send(Buffer.from("Test message 7"), { publishingId: 7n }) //this will be sent since 7 is greater than 3, the last highest publishingId | ||
dc1992 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await secondDeduplicationPublisher.flush() | ||
| const secondPublisherPublishingId = await secondDeduplicationPublisher.getLastPublishingId() | ||
| await secondDeduplicationPublisher.close() | ||
|
|
||
| console.log(`Publishing id is ${secondPublisherPublishingId} (must be 7)`) //this must be the greatest publishingId sent, 7 in this case | ||
|
|
||
| await client.deleteStream({ stream: streamName }) | ||
|
|
||
| await client.close() | ||
| } | ||
|
|
||
| main() | ||
| .then(() => console.log("done!")) | ||
| .catch((res) => { | ||
| console.log("ERROR ", res) | ||
| process.exit(-1) | ||
| }) | ||
| const sleep = (ms) => new Promise((r) => setTimeout(r, ms)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.