Lightweight stream-oriented messaging library for node.
Lightweight stream oriented full-stack messaging library.
pub/sub messaging patterns. Messaging pattern is high level concept of how messages should be handled on sending and receiving. It's
client/server & transport agnostic which means you can use all 4 types of messaging pattern no matter you are connected to a server or being connected from a client with any of the transports supported.
request will be sent to
one connected client/server and wait for
response (round-robin scheduler).
// example/rep.jsvar socketmq = require'../'var smq = socketmqbind'tcp://127.0.0.1:6363'smqon'bind'console.log'rep bound'var event = 'hello' // or you can call it topic or channel.smqon'connect'console.log'new connection'smqreqevent 'request from server'console.logmsgsmqrepeventconsole.log'requested msg:' + msgreply'Hi ' + msg + ', world!'
// example/req.jsvar socketmq = require'socketmq'var smq = socketmqconnect'tcp://127.0.0.1:6363'smqon'connect'console.log'req connected to server'setIntervalsmqreq'hello' 'socketmq.req'console.log'replied msg:' + msg1000smqrep'hello'console.log'request from server' msgreply'response from client'
pub message will be distributed to all client/server connected and no response will be sent back. It's a fire and forget messaging pattern. Pub messages could be received by subscribing to the publishing topic.
// example/pub.jsvar socketmq = require'socketmq'var smq = socketmqconnect'tcp://0.0.0.0:6363'smqon'connect'console.log'pub connected';setIntervalsmqpub'pub.test' 'hello'1000
// example/sub.jsvar socketmq = require'socketmq'var smq = socketmqbind'tcp://127.0.0.1:6363'smqon'bind'console.log'sub bound'smqsub'pub.test'console.log'got pub message: ' + data
SocketMQ can tag the streams and send messages to streams with specific tags.
var socketmq = require'socketmq'var tcpUri = 'tcp://127.0.0.1:6363'var smq = socketmqconnecttcpUri// Tag the stream.smqtagstream 'tcp'var tlsUri = 'tls://127.0.0.1:46363'smqconnecttlsUrismqtagstream 'tls'// Then send messages using `reqTag` of `pubTag`// `req` message only to server with `tcp` tagsmqreqTag'tcp' 'hello' 'message'// ...// `pub` message only to server with `tls` tagsmqpubTag'tls' 'hello' 'message'