1.4.1 • Published 5 years ago

@optum/knack-producer-client v1.4.1

Weekly downloads
10
License
Apache-2.0
Repository
github
Last release
5 years ago

Usage

first things first...

$ npm i @optum/knack-producer-client node-rdkafka@2.7

options

  • useHighLevelProducer: [Boolean] flag indicating to use the highlevel producer over the standard one
  • producerConfig: [Object] librd producer config
  • srOptions: [Object]: options to pass to knack-sr

Examples

simple

const KnackProducerClient = require("@optum/knack-producer-client");

const options = {
	producerConfig: {
		"metadata.broker.list": ["localhost:9092"]
	},
	srOptions: {
		url: "http://localhost:8081"
	}
};

const topic = "knack-test-topic-v1";
const key = { id: "1234" };
const value = { content: "from knack producer client" };

// await getting the producer so it lazy loads a connection the first time a message goes through
const producer = await KnackProducerClient.resolveInstance(options);

producer.publish({
	topic,
	key,
	value
});

// calling for an instance with the same options with give back the same producer, so it will manage different connections for you
const queued = KnackProducerClient.resolveInstance(options).publish({
	topic,
	key,
	value
});

also simple, but one more step

const KnackProducerClient = require("@optum/knack-producer-client");

const options = {
	producerConfig: {
		"metadata.broker.list": ["localhost:9092"]
	},
	srOptions: {
		url: "http://localhost:8081"
	}
};

const topic = "knack-test-topic-v1";
const key = { id: "1234" };
const value = { content: "from knack producer client" };

// connect at app start up or whenever
await KnackProducerClient.connectInstance(options);

// grab the producer through the instance method without needing to await it
const producer = KnackProducerClient.instance(options);

producer.publish({
	topic,
	key,
	value
});
1.4.1

5 years ago

1.2.0

5 years ago

1.4.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.4.0

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago