-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into offset-tracking-example
- Loading branch information
Showing
17 changed files
with
259 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ dist/ | |
node_modules/ | ||
performance_test/node_modules | ||
.envrc | ||
tls-gen/ |
This file contains 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 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 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 |
---|---|---|
@@ -1 +1 @@ | ||
[rabbitmq_management,rabbitmq_prometheus,rabbitmq_stream_management]. | ||
[rabbitmq_management,rabbitmq_prometheus,rabbitmq_stream_management,rabbitmq_auth_mechanism_ssl]. |
This file contains 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,15 @@ | ||
loopback_users.guest = false | ||
|
||
ssl_options.cacertfile = /certs/ca_certificate.pem | ||
ssl_options.certfile = /certs/server_rabbitmq_certificate.pem | ||
ssl_options.keyfile = /certs/server_rabbitmq_key.pem | ||
listeners.ssl.default = 5671 | ||
listeners.tcp.default = 5672 | ||
stream.listeners.tcp.default = 5552 | ||
stream.listeners.ssl.default = 5551 | ||
auth_mechanisms.1 = PLAIN | ||
auth_mechanisms.2 = EXTERNAL | ||
ssl_options.verify = verify_peer | ||
ssl_options.fail_if_no_peer_cert = false | ||
log.file.level = debug | ||
log.console = true |
This file contains 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 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,59 @@ | ||
const rabbit = require("rabbitmq-stream-js-client") | ||
|
||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)) | ||
|
||
async function main() { | ||
console.log("Connecting...") | ||
const client = await rabbit.connect({ | ||
hostname: "localhost", | ||
port: 5552, | ||
username: "rabbit", | ||
password: "rabbit", | ||
vhost: "/", | ||
}) | ||
|
||
console.log("Making sure the stream exists...") | ||
const streamName = "stream-offset-tracking-javascript" | ||
await client.createStream({ stream: streamName, arguments: {} }) | ||
|
||
const consumerRef = "offset-tracking-tutorial" | ||
let firstOffset = undefined | ||
let offsetSpecification = rabbit.Offset.first() | ||
try { | ||
const offset = await client.queryOffset({ reference: consumerRef, stream: streamName }) | ||
offsetSpecification = rabbit.Offset.offset(offset + 1n) | ||
} catch (e) {} | ||
|
||
let lastOffset = offsetSpecification.value | ||
let messageCount = 0 | ||
const consumer = await client.declareConsumer( | ||
{ stream: streamName, offset: offsetSpecification, consumerRef }, | ||
async (message) => { | ||
messageCount++ | ||
if (!firstOffset && messageCount === 1) { | ||
firstOffset = message.offset | ||
console.log("First message received") | ||
} | ||
if (messageCount % 10 === 0) { | ||
await consumer.storeOffset(message.offset) | ||
} | ||
if (message.content.toString() === "marker") { | ||
console.log("Marker found") | ||
lastOffset = message.offset | ||
await consumer.storeOffset(message.offset) | ||
await consumer.close() | ||
} | ||
} | ||
) | ||
|
||
console.log(`Start consuming...`) | ||
await sleep(2000) | ||
console.log(`Done consuming, first offset was ${firstOffset}, last offset was ${lastOffset}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((res) => { | ||
console.log("Error while receiving message!", res) | ||
process.exit(-1) | ||
}) |
This file contains 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,36 @@ | ||
const rabbit = require("rabbitmq-stream-js-client") | ||
|
||
async function main() { | ||
console.log("Connecting...") | ||
const client = await rabbit.connect({ | ||
vhost: "/", | ||
port: 5552, | ||
hostname: "localhost", | ||
username: "rabbit", | ||
password: "rabbit", | ||
}) | ||
|
||
console.log("Making sure the stream exists...") | ||
const streamName = "stream-offset-tracking-javascript" | ||
await client.createStream({ stream: streamName, arguments: {} }) | ||
|
||
console.log("Creating the publisher...") | ||
const publisher = await client.declarePublisher({ stream: streamName }) | ||
|
||
const messageCount = 100 | ||
console.log(`Publishing ${messageCount} messages`) | ||
for (let i = 0; i < messageCount; i++) { | ||
const body = i === messageCount - 1 ? "marker" : `hello ${i}` | ||
await publisher.send(Buffer.from(body)) | ||
} | ||
|
||
console.log("Closing the connection...") | ||
await client.close() | ||
} | ||
|
||
main() | ||
.then(() => console.log("done!")) | ||
.catch((res) => { | ||
console.log("Error in publishing message!", res) | ||
process.exit(-1) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
Oops, something went wrong.