@itentialopensource/adapter-kafkav2 0.15.0 → 0.16.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ## 0.16.1 [08-24-2023]
3
+
4
+ * Handle empty topics file
5
+
6
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!13
7
+
8
+ ---
9
+
10
+ ## 0.16.0 [08-23-2023]
11
+
12
+ * Add logic to clean topics.json from service config
13
+
14
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!11
15
+
16
+ ---
17
+
2
18
  ## 0.15.0 [08-04-2023]
3
19
 
4
20
  * Add logic to clean topics.json from service config
package/README.md CHANGED
@@ -351,7 +351,7 @@ Once you have the adapter configured and online in an IAP instance, you can crea
351
351
 
352
352
  ### Listen to a topic called test-topic and trigger a workflow called test
353
353
 
354
- 1. Subscribe to partition 0 of test-topic. Add this to your adapter service config. To see different options of topic properties see PROPERTIES.md
354
+ 1. Subscribe to partition 0 of test-topic. Add this to your adapter service config. To see different options of topic properties see Topic Properties.
355
355
 
356
356
  ```json
357
357
  "topics": [
@@ -371,7 +371,7 @@ Once you have the adapter configured and online in an IAP instance, you can crea
371
371
  ],
372
372
  ```
373
373
 
374
- Note the rabbit key in the config is set to kafka. The adapter will send any message on test-topic-rabbit to a Rabbit queue named kafka. If no rabbit topic is supplied, events will be published to a topic with the same name as the Kafka topic. Also note that the filter array can be left empty to consume all messages on partion 0 of test-topic.
374
+ Note the rabbit key in the config is set to test-topic-rabbit. The adapter will send any message on test-topic to a Rabbit queue named test-topic-rabbit. If no rabbit topic is supplied, events will be published to a topic with the same name as the Kafka topic. Also note that the filter array can be left empty to consume all messages on partion 0 of test-topic.
375
375
 
376
376
  2. Create an automation in Operations Manager
377
377
 
package/adapter.js CHANGED
@@ -181,13 +181,31 @@ class Kafkav2 extends AdapterBaseCl {
181
181
  this.topicsEvents = [];
182
182
  let topicsFile = path.join(__dirname, `/.topics-${this.id}.json`);
183
183
 
184
- // if the file does not exist - error
184
+ // Check if the file exists
185
185
  if (fs.existsSync(topicsFile)) {
186
- this.topicsEvents = JSON.parse(fs.readFileSync(topicsFile, 'utf-8'));
186
+ const fileContent = fs.readFileSync(topicsFile, 'utf-8');
187
+
188
+ // Check if the file is empty
189
+ if (fileContent.trim() === '') {
190
+ // If it's empty, write an empty array to the file
191
+ fs.writeFileSync(topicsFile, '[]');
192
+ } else {
193
+ // Parse the existing content
194
+ this.topicsEvents = JSON.parse(fileContent);
195
+ }
187
196
  } else if (fs.existsSync(path.join(__dirname, '/.topics.json'))) {
188
197
  log.debug('Found old .topics.json file.');
189
198
  topicsFile = path.join(__dirname, '/.topics.json');
190
- this.topicsEvents = JSON.parse(fs.readFileSync(topicsFile, 'utf-8'));
199
+ const fileContent = fs.readFileSync(topicsFile, 'utf-8');
200
+
201
+ // Check if the file is empty
202
+ if (fileContent.trim() === '') {
203
+ // If it's empty, write an empty array to the file
204
+ fs.writeFileSync(topicsFile, '[]');
205
+ } else {
206
+ // Parse the existing content
207
+ this.topicsEvents = JSON.parse(fileContent);
208
+ }
191
209
  }
192
210
 
193
211
  // get the topics into the right format --- fix older .topics.json files so they have the right format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-kafkav2",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "description": "Itential adapter to connect to kafka",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.35.0",
Binary file