Skip to content

Commit ae84687

Browse files
authored
Merge pull request #371 from Accenture/audit-fixes
Updated examples and fixed npm audit reports
2 parents 344568f + c652b09 commit ae84687

File tree

11 files changed

+2784
-2729
lines changed

11 files changed

+2784
-2729
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4343
More information, follow the [deployment Readme](./deployment/README.md). [#319](https://github.com/Accenture/reactive-interaction-gateway/issues/319)
4444
- make README smaller, easier to read and highlight features. [#284](https://github.com/Accenture/reactive-interaction-gateway/issues/284)
4545
- Updated Phoenix LiveDashboard setup to show also metrics based on the Prometheus metrics (for now only proxy and events metrics). [#157](https://github.com/Accenture/reactive-interaction-gateway/issues/157)
46+
- Updated [Channels Example](https://github.com/Accenture/reactive-interaction-gateway/tree/master/examples/channels-example) to use [Kafkajs](https://kafka.js.org/) and NodeJS 14. Updated [Smoke Tests](https://github.com/Accenture/reactive-interaction-gateway/tree/master/smoke_tests) to use NodeJS 14.
4647

4748
### Fixed
4849

examples/channels-example/frontend/package-lock.json

Lines changed: 2483 additions & 2299 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/channels-example/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"react-dom": "^16.8.6"
1111
},
1212
"devDependencies": {
13-
"react-scripts": "^4.0.0"
13+
"react-scripts": "^4.0.3"
1414
},
1515
"scripts": {
1616
"start": "react-scripts start",

examples/channels-example/frontend/src/components/Channels/Message.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class Message extends PureComponent {
4141
);
4242
}
4343

44-
successCall(message) {
44+
successCall() {
4545
return (
4646
<p className="notification is-success">
47-
Successful REST API call. Response <strong>{message}</strong>.
47+
Successful REST API call.
4848
</p>
4949
);
5050
}
@@ -62,7 +62,7 @@ class Message extends PureComponent {
6262
const messageString = JSON.stringify(callStatus.message);
6363

6464
if (callStatus.status === 'ok') {
65-
return this.successCall(messageString);
65+
return this.successCall();
6666
}
6767
return this.errorCall(messageString);
6868
})()}

examples/channels-example/service/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:10-alpine
1+
FROM node:14-alpine
22

33
# Set working directory
44
WORKDIR /opt/service/
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict';
22

3-
const Hapi = require('hapi');
3+
const Hapi = require('@hapi/hapi');
44
const kafkaRoutes = require('./kafka/kafka-routes');
55

66
const port = 8000;
7-
const server = new Hapi.Server({ port });
7+
const server = Hapi.server({
8+
port,
9+
});
810

911
server.route(kafkaRoutes);
1012

1113
const init = async () => {
12-
await server.start();
13-
console.log(`Server running at: ${server.info.uri}`);
14+
await server.start();
15+
console.log(`Server running at: ${server.info.uri}`);
1416
};
1517

1618
process.on('unhandledRejection', (err) => {
17-
console.log(err);
18-
process.exit(1);
19+
console.log(err);
20+
process.exit(1);
1921
});
2022

2123
init();
Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
'use strict';
22

3-
const kafka = require('no-kafka');
3+
const { Kafka } = require('kafkajs');
44

55
const KAFKA_HOSTS = process.env.KAFKA_HOSTS || 'localhost:9092';
66
const KAFKA_SOURCE_TOPICS = process.env.KAFKA_SOURCE_TOPICS || 'example';
77

8-
const kafkaProducer = (message) => {
9-
const producer = new kafka.Producer({
10-
connectionString: KAFKA_HOSTS,
11-
});
12-
13-
const stringMessageValue = JSON.stringify(message);
14-
15-
return producer.init()
16-
.then(() => {
17-
const data = {
18-
topic: KAFKA_SOURCE_TOPICS,
19-
message: {
20-
value: stringMessageValue,
21-
},
22-
};
23-
24-
return producer.send(data);
25-
})
26-
.then((result) => {
27-
producer.end();
28-
29-
const { error } = result[0];
30-
if (error) {
31-
return error;
32-
}
33-
34-
console.log(`Message successfully produced to Kafka ${JSON.stringify(result)}`);
35-
return result;
36-
})
37-
.catch((e) => {
38-
console.log(`Could not produce message to topic ${KAFKA_SOURCE_TOPICS}`);
39-
console.log(e);
40-
producer.end();
41-
return e;
42-
});
43-
};
8+
const kafka = new Kafka({
9+
clientId: 'channel-service',
10+
brokers: [KAFKA_HOSTS],
11+
});
12+
const producer = kafka.producer();
4413

4514
exports.produce = {
46-
handler: (request) => {
47-
const msg = request.payload;
48-
49-
return kafkaProducer(msg)
50-
.then(message => ({ status: 'ok', message }))
51-
.catch(message => ({ status: 'error', message }));
52-
},
15+
handler: async (request) => {
16+
const msg = request.payload;
17+
18+
try {
19+
await producer.connect();
20+
await producer.send({
21+
topic: KAFKA_SOURCE_TOPICS,
22+
messages: [{ value: JSON.stringify(msg) }],
23+
});
24+
await producer.disconnect();
25+
console.log('Message successfully produced to Kafka');
26+
27+
return { status: 'ok' };
28+
} catch (error) {
29+
console.error('Failed to produce message to Kafka', error);
30+
return { status: 'error', message: error };
31+
}
32+
},
5333
};

examples/channels-example/service/kafka/kafka-routes.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
const kafkaController = require('./kafka-ctrl');
44

55
module.exports = [
6-
{
7-
method: 'POST',
8-
path: '/produce',
9-
config: kafkaController.produce,
10-
},
6+
{
7+
method: 'POST',
8+
path: '/produce',
9+
config: kafkaController.produce,
10+
},
1111
];

0 commit comments

Comments
 (0)