@glowlabs-org/events-sdk 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/emitter.js CHANGED
@@ -20,7 +20,12 @@ function createGlowEventEmitter({ username, password, zoneId, exchangePrefix = "
20
20
  async function connectIfNeeded() {
21
21
  if (!amqpConnection) {
22
22
  amqpConnection = (await amqplib_1.default.connect(buildUrl()));
23
- amqpChannel = (await amqpConnection.createChannel());
23
+ // create a confirm channel so we can wait for broker acknowledgements
24
+ amqpChannel = (await amqpConnection.createConfirmChannel());
25
+ // if a message is unroutable this handler will fire
26
+ amqpChannel.on("return", (msg) => {
27
+ console.error("❌ UNROUTABLE:", msg.fields.routingKey);
28
+ });
24
29
  }
25
30
  if (amqpChannel) {
26
31
  await amqpChannel.assertExchange(globalExchangeName, "topic", {
@@ -52,8 +57,12 @@ function createGlowEventEmitter({ username, password, zoneId, exchangePrefix = "
52
57
  const routingKey = `${event.eventType}.${event.schemaVersion.toString()}`;
53
58
  await connectIfNeeded();
54
59
  // Emit to both the global and the specific zone exchange
55
- amqpChannel.publish(globalExchangeName, routingKey, Buffer.from(JSON.stringify(event)), { persistent: true });
56
- amqpChannel.publish(zoneExchangeName, routingKey, Buffer.from(JSON.stringify(event)), { persistent: true });
60
+ const globalPublish = amqpChannel.publish(globalExchangeName, routingKey, Buffer.from(JSON.stringify(event)), { persistent: true, mandatory: true });
61
+ const zonePublish = amqpChannel.publish(zoneExchangeName, routingKey, Buffer.from(JSON.stringify(event)), { persistent: true, mandatory: true });
62
+ console.log("globalPublish", globalPublish);
63
+ console.log("zonePublish", zonePublish);
64
+ // Wait for broker to acknowledge publishes; rejects on nack
65
+ await amqpChannel.waitForConfirms();
57
66
  }
58
67
  async function disconnect() {
59
68
  if (amqpConnection) {
package/dist/listener.js CHANGED
@@ -52,6 +52,12 @@ function createGlowEventListener({ username, password, zoneId, queueName, exchan
52
52
  throw new Error("Queue not initialized");
53
53
  consumerTag = (await amqpChannel.consume(internalQueueName, (msg) => {
54
54
  if (msg) {
55
+ // Only process messages that originated from the exchange that matches the requested zoneId.
56
+ // This prevents duplicate handling when the queue is bound to multiple exchanges.
57
+ if (msg.fields.exchange !== exchangeName) {
58
+ amqpChannel.ack(msg);
59
+ return;
60
+ }
55
61
  try {
56
62
  const decoded = JSON.parse(msg.content.toString());
57
63
  const [eventType, versionStr] = msg.fields.routingKey.split(".v");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glowlabs-org/events-sdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Typed event SDK for Glow, powered by RabbitMQ and Zod.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",