1.0.2 • Published 2 years ago

msg-producer v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

基于node-rdkafka支持使用VPC网络或公网 SASL方式接入消息队列CKafka并向CKafka topic中写入消息。

安装

npm i msg-producer

例子

生产者默认配置

{
	'api.version.request': 'true',
	'bootstrap.servers': this.options.server, // array type
	retries: '3', // 请求发生错误时重试次数,建议将该值设置为大于0,失败重试最大程度保证消息不丢失
	'retry.backoff.ms': 100, // 发送请求失败时到下一次重试请求之间的时间
	'socket.timeout.ms': 6000, // producer 网络请求的超时时间。
	dr_cb: true, // Delivery report callback
};

VPC网络接入

若不想使用默认配置,或希望在默认配置的基础上初始化producer时,可通过extra属性添加额外配置。

const PubMsg = require('msg-producer');

const p = new PubMsg({
	server: ['server'],
});

p.produceMsg({ topic: 'topic', msg: 'hello vpc' });

公网接入

以下实例为公网SASL_PLAINTEXT接入CKafka的示例。

const PubMsg = require('msg-producer');

const p = new PubMsg({
	server: ['server'],
	extra: {
		'security.protocol': 'SASL_PLAINTEXT',
		'sasl.mechanisms': 'PLAIN',
		'sasl.username': 'username',
		'sasl.password': 'password',
	},
});

p.produceMsg({ topic: 'your-topic', msg: 'hello sasl' });
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago