@yarkivaev/source-to-sink 1.2.3 → 1.2.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.
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.4",
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
  }
@@ -101,15 +101,13 @@ export default function stompSource(url, destination, collector, options = {}) {
101
101
  const channel = new stompit.Channel(failover);
102
102
  const subscribe = { destination, ack: 'client-individual' };
103
103
  channel.subscribe(subscribe, (err, message) => {
104
- if (err) {
105
- return;
106
- }
107
- message.readString('utf-8', (readErr, body) => {
108
- if (readErr) {
109
- return;
110
- }
111
- collector.accept({ destination, payload: body.toString() });
112
- channel.ack(message);
104
+ if (err) { return; }
105
+ message.readString('utf-8', async (readErr, body) => {
106
+ if (readErr) { return; }
107
+ try {
108
+ await collector.accept({ destination, payload: body.toString() });
109
+ channel.ack(message);
110
+ } catch { channel.nack(message); }
113
111
  });
114
112
  });
115
113
  state = subscribed(channel);