0.1.6 • Published 10 years ago

esb-node-driver v0.1.6

Weekly downloads
2
License
LGPL3
Repository
github
Last release
10 years ago

ESB-node-driver

ESB nodejs driver - under heavy development

Installation

You need to install zeromq 4 and google protobuf. And then:

npm install esb-node-driver

You will need a redis server, place his ip into /etc/hosts as domain esb-redis.

Usage

var ESB = require('esb-node-driver');

var esb = new ESB({
	//your hostname, needed for back connection from ESB proxy
	publisherHost: 'h0x91b.toyga.local',
	//some free port for listen on it
	publisherPort: 7786,
	
	//Hostname with redis, redis used for proxy registry, place it in /etc/hosts
	redisHost: 'esb-redis',
	redisPort: 6379
});

esb.on('error', function(err){
	console.log('ESB error', err);
});

esb.on('ready', function(){
	console.log('ESB ready for use');
	
	//register some method that will be accessed from any client ESB
	esb.register('/math/plus', 1, function(data, cb){
		console.log('/math/plus cb #1 is invoked with data: ', data);
		cb(null, data.a + data.b);
	});
	
	//you can register any number of responders for same identifier
	esb.register('/math/plus', 1, function(data, cb){
		console.log('/math/plus cb #2 is invoked with data: ', data);
		cb(null, data.a + data.b);
	});
	
	//pubsub :)
	esb.subscribe('/hello', 1, function(data){
		console.log('get message on channel /hello', data);
	});
	
	setInterval(function(){
		
		//lets invoke method above every second
		esb.invoke('/math/plus', {a: 2, b: 3}, function(err, resp, errStr){
			if(err){
				console.log('error while invoking a /math/plus', err, errStr);
				return;
			}
			console.assert(resp == 5);
			console.log('2+3=%s', resp);
		});
		
		//publish something
		esb.publish('/hello', {foo:'bar', rand: Math.random()});
		
	}, 1000);
});

API

  • ESB.register(<identifier>, <version>, <callback> ,options)

    	Currently is no options here
  • ESB.invoke(<identifier>, <data>, <callback> ,options)

    	Options may contain:
    
    	* version - by default version is 1
    	* timeout - in ms, by default 15000
  • ESB.publish(<identifier>, <data> ,options)

    	Options may contain:
    
    	* version - by default version is 1
  • ESB.subscribe(<identifier>, <version>, <callback>)

  • ESB.regQueue(<channelName>, <persistentQueueName>)

    	This will make a persistent queue &lt;persistentQueueName> from any publish
  • ESB.unregQueue(<channelName>, <persistentQueueName>)

    	This will destroy persistent queue
  • ESB.peek(<channelName>, <persistentQueueName>, <timeoutMs>, <callback>)
    	Peek & lock entry from persistent queue for &lt;timeoutMs> or until `done` callback fired
    
    	* callback -> function(msg, done, msgId)
    	
    		msg - message
    		done - done callback, fire it for dequeue
    		msgId - autoincrement id used internally in ESB

Issues

If you get error similar to this

module.js:356
  Module._extensions[extension](this, filename);
                               ^
Error: libzmq.so.3: cannot open shared object file: No such file or directory
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/root/node_modules/ESB-proxy-server/main.js:7:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

You need to add export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" to your ~/.bashrc

Building zmq and protobuf from source

#ZMQ
cd /tmp/
wget http://download.zeromq.org/zeromq-4.0.3.tar.gz
tar -xzvf zeromq-4.0.3.tar.gz
cd zeromq-*
./configure && make && sudo make install
#protobuf
cd /tmp/
wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz
tar -xzvf protobuf-2.5.0.tar.gz
cd protobuf-2.5.0/
./configure && make && sudo make install
0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago