@itentialopensource/adapter-kafkav2 0.11.0 → 0.13.0

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.13.0 [08-03-2023]
3
+
4
+ * Add seperate sasl props for consumer and producer
5
+
6
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!10
7
+
8
+ ---
9
+
10
+ ## 0.12.0 [08-03-2023]
11
+
12
+ * Add seperate sasl props for consumer and producer
13
+
14
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!10
15
+
16
+ ---
17
+
2
18
  ## 0.11.0 [08-01-2023]
3
19
 
4
20
  * Add seperate sasl props for consumer and producer
package/README.md CHANGED
@@ -75,6 +75,39 @@ git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafkav2
75
75
  npm install
76
76
  ```
77
77
 
78
+ ## Installing an Itential Product Adapter
79
+
80
+ 1. Set up the name space location in your IAP node_modules.
81
+
82
+ ```json
83
+ cd /opt/pronghorn/current/node_modules
84
+ if the @itentialopensource directory does not exist, create it:
85
+ mkdir @itentialopensource
86
+ ```
87
+
88
+ 1. Clone the adapter into your IAP environment.
89
+
90
+ ```json
91
+ cd \@itentialopensource
92
+ git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafka
93
+ ```
94
+
95
+ 1. Install the dependencies for the adapter.
96
+
97
+ ```json
98
+ cd adapter-Kafka
99
+ npm install
100
+ ```
101
+
102
+ 1. Add the adapter properties for Kafka (created from Adapter Builder) to the `properties.json` file for your Itential build. You will need to change the credentials and possibly the host information below.
103
+ [Kafka sample properties](sampleProperties.json)
104
+
105
+ 1. Restart IAP
106
+
107
+ ```json
108
+ systemctl restart pronghorn
109
+ ```
110
+
78
111
  ## Adapter Properties and Descriptions
79
112
 
80
113
  This section defines **all** the properties that are available for the adapter, including detailed information on what each property is for. If you are not using certain capabilities with this adapter, you do not need to define all of the properties. An example of how the properties for this adapter can be used with tests or IAP are provided in the **Installation** section.
@@ -96,16 +129,7 @@ This section defines **all** the properties that are available for the adapter,
96
129
  "brokers": [
97
130
  "broker:9093"
98
131
  ],
99
- "clientId": "my-app",
100
- "connectTimeout": 10000,
101
- "requestTimeout": 30000,
102
- "autoConnect": true,
103
- "connectRetryOptions": {},
104
- "idleConnection": 300000,
105
- "reconnectOnIdle": true,
106
- "maxAsyncRequests": 10,
107
- "ssl": {},
108
- "sasl": {}
132
+ "clientId": "my-app"
109
133
  },
110
134
  "producer": {
111
135
  "requireAcks": 1,
@@ -113,15 +137,7 @@ This section defines **all** the properties that are available for the adapter,
113
137
  "partitionerType": 0
114
138
  },
115
139
  "consumer": {
116
- "groupId": "kafka-node-group",
117
- "autoCommit": false,
118
- "autoCommitIntervalMs": 5000,
119
- "fetchMaxWaitMs": 100,
120
- "fetchMinBytes": 1,
121
- "fetchMaxBytes": 1048576,
122
- "fromOffset": true,
123
- "encoding": "utf8",
124
- "keyEncoding": "utf8"
140
+ "groupId": "kafka-node-group"
125
141
  }
126
142
  }
127
143
  ```
@@ -262,10 +278,10 @@ These base properties are used to connect to Kafka upon the adapter initially co
262
278
 
263
279
  | Property | Description |
264
280
  | ------- | ------- |
265
- | host | Optional. A fully qualified domain name or IP address.|
266
- | port | Required if `host` set. Used to connect to the server.|
281
+ | host | Optional. A fully qualified domain name or IP address. This is not needed for latest version of the adapter as the broker is set under client properties.|
282
+ | port | Required if `host` set. Used to connect to the server. This is not needed for latest version of the adapter as the port is set under client properties|
267
283
  | interval_time | Optional. The Kafka adapter keeps information about topics and offsets in memory in order to be more efficient. In order to work across restarts the adapter must persist the data. So the data is written into the .topics.json file. This write time defines how often to write the file.|
268
- | stub | Optional. Slightlu different meaning than normal, this is just telling the adapter whether to run the write topics interval. This should always be false unless you are running standalone tests.|
284
+ | stub | Optional. Slightly different meaning than normal, this is just telling the adapter to not actually send any request to kafka and mock a healthy connection. Should be set to false unless you are wanting to force the adapter to be green without an actual connection.|
269
285
 
270
286
  #### Important
271
287
  When adapter works in consumer configuration: `autoCommit:false` `fromOffset:true` current offset setting on adapter startup is loaded from .topic.json file for each (topic:partition).
@@ -302,14 +318,7 @@ The following properties are used to define the Kafka Consumer. These properties
302
318
  | Property | Description |
303
319
  | ------- | ------- |
304
320
  | groupId | consumer group id, default `kafka-node-group`.|
305
- | autoCommit | Auto commit config.|
306
- | autoCommitIntervalMs | |
307
- | fetchMaxWaitMs | max wait time is the maximum amount of time in milliseconds to block waiting if insufficient data is available at the time the request is issued, default 100ms|
308
- | fetchMinBytes | minimum number of bytes of messages that must be available to give a response, default 1 byte.|
309
- | fetchMaxBytes | maximum bytes to include in the message set for this partition. This helps bound the size of the response.|
310
- | fromOffset | If set true, consumer will fetch message from the given offset in the payloads.|
311
- | encoding | If set to 'buffer', values will be returned as raw buffer objects..|
312
- | keyEncoding | |
321
+
313
322
 
314
323
  ## Parsing Properties
315
324
 
@@ -323,6 +332,8 @@ The `parseMessage` property allows the user to define how they want the Kafka me
323
332
 
324
333
  ## Send message sample payload
325
334
 
335
+ Note that this is an array, so it can have multiple topics.
336
+
326
337
  ```json
327
338
  [{
328
339
  "topic": "topic-name",
@@ -334,122 +345,42 @@ The `parseMessage` property allows the user to define how they want the Kafka me
334
345
  ```
335
346
  For all options of messages array please follow [kafkajs documentation](https://kafka.js.org/docs/producing#producing-messages)
336
347
 
337
- ## Testing an Itential Product Adapter
338
-
339
- Mocha is generally used to test all Itential Product Adapters. There are unit tests as well as integration tests performed. Integration tests can generally be run as standalone using mock data and running the adapter in stub mode, or as integrated. When running integrated, every effort is made to prevent environmental failures, however there is still a possibility.
340
-
341
- ### Unit Testing
342
-
343
- Unit Testing includes testing basic adapter functionality as well as error conditions that are triggered in the adapter prior to any integration. There are two ways to run unit tests. The prefered method is to use the testRunner script; however, both methods are provided here.
344
-
345
-
346
- ```json
347
- node utils/testRunner --unit
348
-
349
- npm run test:unit
350
- ```
351
-
352
- To add new unit tests, edit the `test/unit/adapterTestUnit.js` file. The tests that are already in this file should provide guidance for adding additional tests.
353
-
354
- ### Integration Testing - Standalone
355
-
356
- Standalone Integration Testing requires mock data to be provided with the entities. If this data is not provided, standalone integration testing will fail. When the adapter is set to run in stub mode (setting the stub property to true), the adapter will run through its code up to the point of making the request. It will then retrieve the mock data and return that as if it had received that data as the response from Kafka. It will then translate the data so that the adapter can return the expected response to the rest of the Itential software. Standalone is the default integration test.
357
-
358
- Similar to unit testing, there are two ways to run integration tests. Using the testRunner script is better because it prevents you from having to edit the test script; it will also resets information after testing is complete so that credentials are not saved in the file.
359
-
360
- ```json
361
- node utils/testRunner
362
- answer no at the first prompt
363
-
364
- npm run test:integration
365
- ```
366
-
367
- To add new integration tests, edit the `test/integration/adapterTestIntegration.js` file. The tests that are already in this file should provide guidance for adding additional tests.
368
-
369
- ### Integration Testing
370
-
371
- Integration Testing requires connectivity to Kafka. By using the testRunner script it prevents you from having to edit the integration test. It also resets the integration test after the test is complete so that credentials are not saved in the file.
372
-
373
- > **Note**: These tests have been written as a best effort to make them work in most environments. However, the Adapter Builder often does not have the necessary information that is required to set up valid integration tests. For example, the order of the requests can be very important and data is often required for `creates` and `updates`. Hence, integration tests may have to be enhanced before they will work (integrate) with Kafka. Even after tests have been set up properly, it is possible there are environmental constraints that could result in test failures. Some examples of possible environmental issues are customizations that have been made within Kafka which change order dependencies or required data.
348
+ ## Triggering jobs in IAP from a kafka message
374
349
 
375
- ```json
376
- node utils/testRunner
377
- answer yes at the first prompt
378
- answer all other questions on connectivity and credentials
379
- ```
380
-
381
- Test should also be written to clean up after themselves. However, it is important to understand that in some cases this may not be possible. In addition, whenever exceptions occur, test execution may be stopped, which will prevent cleanup actions from running. It is recommended that tests be utilized in dev and test labs only.
382
-
383
- > **Reminder**: Do not check in code with actual credentials to systems.
384
-
385
- ## Installing an Itential Product Adapter
386
-
387
- 1. Set up the name space location in your IAP node_modules.
388
-
389
- ```json
390
- cd /opt/pronghorn/current/node_modules
391
- if the @itentialopensource directory does not exist, create it:
392
- mkdir @itentialopensource
393
- ```
350
+ Once you have the adapter configured and online in an IAP instance, you can create triggers in Operations Manager to kick off jobs when a kafka message is consumed. The adapter listens for messages on the subscribed topics and publishes to an event. This event is picked up by the Operations Manager. If you have created triggers for this specific topic, a job will get triggered. For a step-by-step example follow the next sub-section.
394
351
 
395
- 1. Clone the adapter into your IAP environment.
352
+ ### Listen to a topic called test-topic and trigger a workflow called test
396
353
 
397
- ```json
398
- cd \@itentialopensource
399
- git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafka
400
- ```
401
-
402
- 1. Install the dependencies for the adapter.
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
403
355
 
404
356
  ```json
405
- cd adapter-Kafka
406
- npm install
407
- ```
408
-
409
- 1. Add the adapter properties for Kafka (created from Adapter Builder) to the `properties.json` file for your Itential build. You will need to change the credentials and possibly the host information below.
410
- [Kafka sample properties](sampleProperties.json)
411
-
412
- 1. Restart IAP
413
-
414
- ```json
415
- systemctl restart pronghorn
416
- ```
417
-
418
- ## Installing a Custom Adapter
419
-
420
- If you built this as a custom adapter through the Adapter Builder, it is recommended you go through setting up a development environment and testing the adapter before installing it. There is often configuration and authentication work that is required before the adapter will work in IAP.
421
-
422
- 1. Move the adapter into the IAP `node_modules` directory.
423
-
424
- ```json
425
- Depending on where your code is located, this process is different.
426
- Could be a tar, move, untar
427
- Could be a git clone of a repository
428
- Could also be a cp -R from a coding directory
429
- Adapter should be placed into: /opt/pronghorn/current/node_modules/\@itentialopensource
357
+ "topics": [
358
+ {
359
+ "name": "test-topic",
360
+ "always": true,
361
+ "partition": 0,
362
+ "subscriberInfo": [
363
+ {
364
+ "subname": "default",
365
+ "filters": [],
366
+ "rabbit": "test-topic-rabbit",
367
+ "throttle": {}
368
+ }
369
+ ]
370
+ }
371
+ ],
430
372
  ```
431
373
 
432
- 1. Follow Steps 3-5 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
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.
433
375
 
434
- ## Using this Adapter
376
+ 2. Create an automation in Operations Manager
435
377
 
436
- The `adapter.js` file contains the calls the adapter makes available to the rest of the Itential Platform. The API detailed for these calls should be available through JSDOC. The following is a brief summary of the calls.
378
+ Create a new automation, and add a trigger.
437
379
 
438
- ### Generic Adapter Calls
439
-
440
- ```json
441
- connect()
442
- The connect call is run when the Adapter is first loaded by he Itential Platform. It validates the properties have been provided correctly.
443
- ```
444
-
445
- ```json
446
- healthCheck(callback)
447
- Insures that the adapter can communicate with Kafka. The actual call that is used is defined in the adapter properties.
448
- ```
380
+ When selecting the Event for your trigger, make sure to select test-topic-rabbit from the drop down list. This is critical as the adpater will be sending the message on this queue. You can add filtering in the trigger by providing a Payload Schema Filter.
449
381
 
450
- ### Specific Adapter Calls
382
+ After saving the trigger, select the workflow you want to trigger. Save the Automation and view all jobs to see a job getting triggered as soon as a message is published on test-topic partition 0.
451
383
 
452
- Specific adapter calls are built based on the API of the Kafka. The Adapter Builder creates the proper method comments for generating JS-DOC for the adapter. This is the best way to get information on the calls.
453
384
 
454
385
  ## Troubleshooting the Adapter
455
386
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-kafkav2",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Itential adapter to connect to kafka",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.35.0",
Binary file