@yarkivaev/source-to-sink 1.2.3 → 1.2.7

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.
@@ -8,5 +8,5 @@ jobs:
8
8
  ci:
9
9
  uses: yarkivaev/npm-workflows/.github/workflows/ci.yml@main
10
10
  with:
11
- node-version: '22'
11
+ node-version: '22.22.1'
12
12
  lint: true
@@ -11,5 +11,5 @@ jobs:
11
11
  contents: write
12
12
  id-token: write
13
13
  with:
14
- node-version: '22'
14
+ node-version: '22.22.1'
15
15
  lint: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yarkivaev/source-to-sink",
3
- "version": "1.2.3",
3
+ "version": "1.2.7",
4
4
  "description": "Generic library for building data streaming pipelines",
5
5
  "repository": {
6
6
  "type": "git",
package/src/batch.js CHANGED
@@ -31,12 +31,8 @@ export default function batch(sink, size, circuit) {
31
31
  }
32
32
  let records = [];
33
33
  function perform() {
34
- if (records.length === 0) {
35
- return;
36
- }
37
- if (!circuit.allowing()) {
38
- return;
39
- }
34
+ if (records.length === 0) { return; }
35
+ if (!circuit.allowing()) { return; }
40
36
  const pending = records;
41
37
  records = [];
42
38
  try {
package/src/mqttSource.js CHANGED
@@ -83,6 +83,9 @@ export default function mqttSource(url, topics, collector, options = {}) {
83
83
  sessionExpiryInterval: options.sessionExpiryInterval || 3600
84
84
  } : undefined
85
85
  });
86
+ // @todo Implement manualAcknowledge to defer ack until batch writes to sink
87
+ // Currently MQTT.js auto-acks after this callback returns, before the batch
88
+ // flushes to the database. Up to 5 seconds of data may be lost on crash
86
89
  function handler(tp, message) {
87
90
  collector.accept({ topic: tp, payload: message.toString() });
88
91
  }
@@ -99,17 +99,18 @@ export default function stompSource(url, destination, collector, options = {}) {
99
99
  maxReconnects: -1
100
100
  });
101
101
  const channel = new stompit.Channel(failover);
102
+ let pending = Promise.resolve();
102
103
  const subscribe = { destination, ack: 'client-individual' };
103
104
  channel.subscribe(subscribe, (err, message) => {
104
- if (err) {
105
- return;
106
- }
105
+ if (err) { return; }
107
106
  message.readString('utf-8', (readErr, body) => {
108
- if (readErr) {
109
- return;
110
- }
111
- collector.accept({ destination, payload: body.toString() });
112
- channel.ack(message);
107
+ if (readErr) { return; }
108
+ pending = pending.then(async () => {
109
+ try {
110
+ await collector.accept({ destination, payload: body.toString() });
111
+ channel.ack(message);
112
+ } catch { channel.nack(message); }
113
+ });
113
114
  });
114
115
  });
115
116
  state = subscribed(channel);