A nodejs client for Hedwig, which is a large scale pub/sub system built on topc of ZooKeeper and BookKeeper.
A nodejs client for Hedwig, which is a large scale pub/sub system built on top of ZooKeeper and BookKeeper.
Create a hedwig client: Hedwig(options, log4j_properties_file_path)
var client = new hedwig.Hedwig(options, './log4cxx.properties');
Construct an operation callback: function(error)
var pubCb = function(error) { if (error) { console.log('pub failed : ' + error); } else { console.log('pub succeed !'); } };
Publish messages: Hedwig#pub(topic, message, callback)
client.pub(topic, "msg", pubCb);
Subscribe topics: Hedwig#sub(topic, subscriber_id, mode, callback)
client.sub(topic, subId, CREATE_OR_ATTACH, subCb);
Unsubscribe topics: Hedwig#unsub(topic, subscriber_id)
client.unsub(topic, subId);
Close subscription: Hedwig#closesub(topic, subscriber_id) (which is different with #unsub, it doesn't remove subscription in server side, just clean client state.)
client.closesub(topic, subId);
Construct a message handler to process received messages: function(topic, subscriber_id, message, consume_callback)
var msgHandler = function(thisTopic, thisSub, message, consumeCb) { console.log('Received message : ' + JSON.stringify(message)); consumeCb.complete(); };
Start to receive messages: Hedwig#startDelivery(topic, subscriber_id, message_handler)
client.startDelivery(topic, subId, msgHandler);
Stop to receive messages: Hedwig#stopDelivery(topic, subscriber_id)
client.stopDelivery(topic, subId);