tcppubsub
A simple and lightweight submarine build with publish-subscribe-request-response-methods. With a broker called broker 🐙 and a client called member 🐬.
A simple and fast exchange of data between nodejs-apps. Use the publish-subscribe-pattern to handle events or use the request-response-pattern to query or serve some data. Otherwise, get into a submarine and look for the octopus.
Installing
npm i tcppubsub
Broker 🐙
A broker handles all data from the members, like sockets, topics and payload. You can use some events to handle the member-data directly at the broker-side.
Example
var tcppubsub = var port = 2223var host = 'localhost'var block = true // block payload sending to publisher, if he has subscribed the topic too. Default: true (blocked) var broker = port host blockbroker broker // Publish on topics from brokerbroker //use the socket-events like:brokerbrokerbrokerbrokerbrokerbroker
Member 🐬
- Publish-subscribe data.
- Listen on requests.
- Query some data from listeners.
- Topic without wildcard 'app/configuration/server' .
- Topic with wildcard 'app/configuration/#' or 'app/#/configuration',....
- Data can be a string or a object and is emitted as a buffer.
- When the broker restarting, it will automatically resubscribe all topics from subscription or listeners.
Connect
Call the connect-method to connect the member.
member
Subscribe
Subscribe a topic. For multiple topics give a array of topics like ['topic1', 'topic2',...].
member
Unsubscribe
Unsubscribe a topic. For multiple topics give a array of topics like ['topic1', 'topic2',...].
member
Publish
Publish some data on a topic.
member
Request
Make a request on a listener topic. Set some timeout in ms for handle timeout-errors. Default-timeout: 10min.
member
Listen
Listen on a specific topic for requests. Handle the data and send the response with res.
member
Message Event
Catch a message-event with namespace message
for receiving all messages or use a specific topic.
member /******* OR *******/ member
Example
var tcppubsub = var port = 2223var host = 'localhost' //Create the membervar member = port host member
Authors
- Yannick Grund (yamicro.io@gmail.com) - Initial work - yamigr
ToDo
- Benchmark tests (broker and members)
License
This project is licensed under the MIT License - see the LICENSE.md file for details