Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
More information, follow the [deployment Readme](./deployment/README.md). [#319](https://github.com/Accenture/reactive-interaction-gateway/issues/319)
- make README smaller, easier to read and highlight features. [#284](https://github.com/Accenture/reactive-interaction-gateway/issues/284)
- 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)
- 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.

### Fixed

Expand Down
4,782 changes: 2,483 additions & 2,299 deletions examples/channels-example/frontend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/channels-example/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react-dom": "^16.8.6"
},
"devDependencies": {
"react-scripts": "^4.0.0"
"react-scripts": "^4.0.3"
},
"scripts": {
"start": "react-scripts start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class Message extends PureComponent {
);
}

successCall(message) {
successCall() {
return (
<p className="notification is-success">
Successful REST API call. Response <strong>{message}</strong>.
Successful REST API call.
</p>
);
}
Expand All @@ -62,7 +62,7 @@ class Message extends PureComponent {
const messageString = JSON.stringify(callStatus.message);

if (callStatus.status === 'ok') {
return this.successCall(messageString);
return this.successCall();
}
return this.errorCall(messageString);
})()}
Expand Down
2 changes: 1 addition & 1 deletion examples/channels-example/service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:10-alpine
FROM node:14-alpine

# Set working directory
WORKDIR /opt/service/
Expand Down
14 changes: 8 additions & 6 deletions examples/channels-example/service/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict';

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

const port = 8000;
const server = new Hapi.Server({ port });
const server = Hapi.server({
port,
});

server.route(kafkaRoutes);

const init = async () => {
await server.start();
console.log(`Server running at: ${server.info.uri}`);
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};

process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
console.log(err);
process.exit(1);
});

init();
68 changes: 24 additions & 44 deletions examples/channels-example/service/kafka/kafka-ctrl.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
'use strict';

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

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

const kafkaProducer = (message) => {
const producer = new kafka.Producer({
connectionString: KAFKA_HOSTS,
});

const stringMessageValue = JSON.stringify(message);

return producer.init()
.then(() => {
const data = {
topic: KAFKA_SOURCE_TOPICS,
message: {
value: stringMessageValue,
},
};

return producer.send(data);
})
.then((result) => {
producer.end();

const { error } = result[0];
if (error) {
return error;
}

console.log(`Message successfully produced to Kafka ${JSON.stringify(result)}`);
return result;
})
.catch((e) => {
console.log(`Could not produce message to topic ${KAFKA_SOURCE_TOPICS}`);
console.log(e);
producer.end();
return e;
});
};
const kafka = new Kafka({
clientId: 'channel-service',
brokers: [KAFKA_HOSTS],
});
const producer = kafka.producer();

exports.produce = {
handler: (request) => {
const msg = request.payload;

return kafkaProducer(msg)
.then(message => ({ status: 'ok', message }))
.catch(message => ({ status: 'error', message }));
},
handler: async (request) => {
const msg = request.payload;

try {
await producer.connect();
await producer.send({
topic: KAFKA_SOURCE_TOPICS,
messages: [{ value: JSON.stringify(msg) }],
});
await producer.disconnect();
console.log('Message successfully produced to Kafka');

return { status: 'ok' };
} catch (error) {
console.error('Failed to produce message to Kafka', error);
return { status: 'error', message: error };
}
},
};
10 changes: 5 additions & 5 deletions examples/channels-example/service/kafka/kafka-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const kafkaController = require('./kafka-ctrl');

module.exports = [
{
method: 'POST',
path: '/produce',
config: kafkaController.produce,
},
{
method: 'POST',
path: '/produce',
config: kafkaController.produce,
},
];
Loading