@axxel/event-bus 1.1.3 → 1.1.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"tokenPriceProducer.d.ts","sourceRoot":"","sources":["../../src/producers/tokenPriceProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAWlC,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,iBAwB7D"}
1
+ {"version":3,"file":"tokenPriceProducer.d.ts","sourceRoot":"","sources":["../../src/producers/tokenPriceProducer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAa,eAAe,EAAE,MAAM,0BAA0B,CAAC;AA+B3E,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,eAAe,iBAwB7D"}
@@ -9,9 +9,24 @@ function normalizePriceMap(price) {
9
9
  }
10
10
  return price;
11
11
  }
12
+ // ---------- Singleton state ----------//
13
+ let producer = null;
14
+ let isConnecting = null;
15
+ async function getProducer() {
16
+ if (!producer) {
17
+ producer = kafka_1.kafka.producer();
18
+ }
19
+ if (!isConnecting) {
20
+ isConnecting = producer.connect().catch((err) => {
21
+ isConnecting = null;
22
+ throw err;
23
+ });
24
+ }
25
+ await isConnecting;
26
+ return producer;
27
+ }
12
28
  async function produceTokenPrice(event) {
13
- const producer = kafka_1.kafka.producer();
14
- await producer.connect();
29
+ const producer = await getProducer();
15
30
  const key = `${event.chainId}:${event.tokenAddress}`;
16
31
  const serializedEvent = {
17
32
  ...event,
@@ -26,6 +41,5 @@ async function produceTokenPrice(event) {
26
41
  },
27
42
  ],
28
43
  });
29
- await producer.disconnect();
30
44
  console.log(`✅ Sent token price update for ${event.symbol ?? event.tokenAddress} (chain ${event.chainId})`);
31
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axxel/event-bus",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Axxel Kafka Event Bus SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",