npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mservicebus

v0.2.3

Published

An AMQP-based service bus for microservice architectures

Downloads

3

Readme

mservicebus

In today's distributed-system architectures, messaging is the integration mechanism of choice. Whether microservices-styled, or actor-model based, Most systems are implemented as message-passing systems. A service bus is an abstraction on message exchange patterns. It is the fabric that holds the components together.

mservicebus is an opinionated implementation of a service bus. With emphasis on ease of use and scalability, it uses nodejs callbacks and streams as abstractions on message exchange patterns. Although it is based on AMQP. It seeks to remove the burden of managing the details about connections, channels, queues, and message acknowledgement. It does however, provide the means to explicitly make some of the important choices when scaling out.

mservicebus support x message patterns:

  • request-response
  • publish-subscribe
  • XXXXXXXX

Getting started

npm install mservicebus

Instantiate and connect to an AMQP message broker such as rabbitmq

var Servicebus = require('mservicebus');

var servicebus = new Servicebus({
	//options for amqp and timeouts
	name: 'myservicebus',	//Will be used as the name of the topic exchange for pubsub 
	timeout: 50000,
	amqp:{
		url:'amqp://localhost:5762',
	}
});

Request-Response

Request-Response is most useful for implementing Actions - commands or queries; in a sense, RPCs(Remote Procedure calls). mservicebus uses node-style callback api for defining and invoking actions.

//Send a request
servicebus.request('myotherservice.query1', {param1:'value1'}, function(err, results){
	// put code to handle error or use results here
});

//Fulfill a request
servicebus.fulfill('myservice.command1', function(request, callback){
		//put code to perform action here
		// this will be the main action 
		// It is the function at the bottom of the stack of function registered
		// for the named action
	})
	.use(function middleware1(request, next){	//use simple middleware
		//put code to execute middleware action
		next();
	})
	.put(1, function middleware3(request, response, next){	//place middleware at index 1
		//put code to execute middleware action
		next();	
	})
	.putBefore('middleware3', function middleware2 (request, response, next){	//put middleware before 'middleware3'
		//put code to execute middleware action
		next();
	})
	.handleError(function(err, args, next){	//use error middleware
		//put code to handle error here
	});

Publish-subscribe

Publish-subscribe is useful for event publication. In many cases, subscribers make changes in response to events. As there may be multiple instances of a given subscriber running concurrently, A clear decision has to made about how to handle such a scenario.

servicebus.subscribe('myotherservice.stock.nyse.#', function(event){
	//put code to handle event here
});

servicebus.publish('myservice.stock.acme', {
	//event data goes here
});

Middleware & Fluent Api

mservicebus provides a fluent api for using middleware functions.

servicebus.fulfill('myservice.command1', function(request, callback){
		//put code to perform action here
		// this will be the main action 
		// It is the function at the bottom of the stack of function registered
		// for the named action
	})
	.use(function middleware1(request, next){	//use simple middleware
		//put code to execute middleware action
		next();
	})
	.put(1, function middleware3(request, response, next){	//place middleware at index 1
		//put code to execute middleware action
		next();	
	})
	.putBefore('middleware3', function middleware2 (request, response, next){	//put middleware before 'middleware3'
		//put code to execute middleware action
		next();
	})
	.handleError(function(err, args, next){	//use error middleware
		//put code to handle error here
	});

Event replay

servicebus.replay('myservice.event.stream', function(args, stream){
	eventStore.getEvent(args, function(events){
		events.forEach(function(event){
			stream.write(event);
		});
		stream.close();
});

servicebus.requestReplay('myotherservice.event.name', function(err, stream){
	//put code to handle error, or read event objects from stream
})

Key design choices.

In the interest of scalability, mservicebus demands that each instance of the servicebus be given a servicename. This allows for load balancing/fair dispatch between multiple instance of the same system comonent.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

TODO: Write history

Credits

Adedayo Omitayo - https://github.com/Aomitayo

License

MIT