Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createConsumer(topic: string) {
// Create a group for each instance. The consumer will receive all messages from the topic
const groupId = this.options.groupId || Math.ceil(Math.random() * 9999)
const stream = Kafka.createReadStream(
Object.assign(
{},
{
'group.id': `kafka-group-${groupId}`,
'metadata.broker.list': this.brokerList(),
},
this.options.globalConfig,
),
{},
{ topics: [topic] }
);
stream.consumer.on('data', (message) => {
let parsedMessage = JSON.parse(message.value.toString())
// Using channel abstraction
if (parsedMessage.channel) {
KafkaPubSub.prototype.createConsumer = function (topic) {
var _this = this;
var groupId = this.options.groupId || Math.ceil(Math.random() * 9999);
var stream = Kafka.createReadStream(Object.assign({}, {
'group.id': "kafka-group-" + groupId,
'metadata.broker.list': this.brokerList(),
}, this.options.globalConfig), {}, { topics: [topic] });
stream.consumer.on('data', function (message) {
var parsedMessage = JSON.parse(message.value.toString());
if (parsedMessage.channel) {
var channel = parsedMessage.channel, payload = __rest(parsedMessage, ["channel"]);
_this.onMessage(parsedMessage.channel, payload);
}
else {
_this.onMessage(topic, parsedMessage);
}
});
return stream;
};
return KafkaPubSub;