mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Add Schema Registry to the Kafka consumer
This commit is contained in:
parent
ea9f956f0d
commit
894ed83efc
|
@ -5,6 +5,8 @@ import {
|
||||||
SASLOptions,
|
SASLOptions,
|
||||||
} from 'kafkajs';
|
} from 'kafkajs';
|
||||||
|
|
||||||
|
import { SchemaRegistry } from '@kafkajs/confluent-schema-registry';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ITriggerFunctions,
|
ITriggerFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
@ -98,6 +100,27 @@ export class KafkaTrigger implements INodeType {
|
||||||
default: 30000,
|
default: 30000,
|
||||||
description: 'The time to await a response in ms.',
|
description: 'The time to await a response in ms.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Use Schema Registry',
|
||||||
|
name: 'useSchemaRegistry',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Use Apache Avro serialization format and Confluent\' wire formats.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Schema Registry URL',
|
||||||
|
name: 'schemaRegistryUrl',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
useSchemaRegistry: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'URL of the schema registry.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -147,6 +170,11 @@ export class KafkaTrigger implements INodeType {
|
||||||
|
|
||||||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||||
|
|
||||||
|
let registry: SchemaRegistry;
|
||||||
|
if (options.useSchemaRegistry) {
|
||||||
|
registry = new SchemaRegistry({ host: options.schemaRegistryUrl as string });
|
||||||
|
}
|
||||||
|
|
||||||
const startConsumer = async () => {
|
const startConsumer = async () => {
|
||||||
await consumer.run({
|
await consumer.run({
|
||||||
eachMessage: async ({ topic, message }) => {
|
eachMessage: async ({ topic, message }) => {
|
||||||
|
@ -160,6 +188,12 @@ export class KafkaTrigger implements INodeType {
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.useSchemaRegistry) {
|
||||||
|
try {
|
||||||
|
value = await registry.decode(message.value as Buffer);
|
||||||
|
} catch (error) { }
|
||||||
|
}
|
||||||
|
|
||||||
data.message = value;
|
data.message = value;
|
||||||
data.topic = topic;
|
data.topic = topic;
|
||||||
|
|
||||||
|
|
|
@ -607,6 +607,7 @@
|
||||||
"typescript": "~3.9.7"
|
"typescript": "~3.9.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@kafkajs/confluent-schema-registry": "1.0.6",
|
||||||
"@types/lossless-json": "^1.0.0",
|
"@types/lossless-json": "^1.0.0",
|
||||||
"@types/promise-ftp": "^1.3.4",
|
"@types/promise-ftp": "^1.3.4",
|
||||||
"@types/snowflake-sdk": "^1.5.1",
|
"@types/snowflake-sdk": "^1.5.1",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": [
|
"lib": [
|
||||||
|
"dom",
|
||||||
"es2017",
|
"es2017",
|
||||||
"es2019.array"
|
"es2019.array"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue