kafka-rest-publisher-client
v2.1.0
Published
A thin wrapper above Kafka REST
Downloads
8
Readme
kafka-rest-publisher-client
A thin wrapper above Kafka REST
Usage
const KafkaRestPublisherClient = require( 'kafka-rest-publisher-client' );
const host = 'http://localhost:8082';
const topic = 'toSpace';
// all message fields are optional
const message = {
key: 'someKey',
value: 'someValue',
partition: 0
} );
const client = new KafkaRestPublisher( { host } );
client.publish( topic, message ) // single message or array
.then( console.log );
/*
offsets: [
{
partition: 0,
offset: 0,
error_code: null,
error: null
}
],
key_schema_id: null,
value_schema_id: null
*/
client.checkConnection()
.then( console.log );
/* true */
Nocker
const kafkaRestNocker = require( 'kafka-rest-publisher-client/nocker' );
const nock = require( 'nock' );
const host = 'http://localhost:8082';
const nocker = kafkaRestNocker( host, nock );
nocker.mockHost(); // Ensures that host is mocked
nocker.mockPublish( host );
nocker.mockPublish( host, {
code: 500,
body: {
message: 'Some error'
}
} );
nocker.mockCheckConnection();
nocker.mockCheckConnection( {
code: 500,
body: {
message: 'Some error'
}
} );