[READ-ONLY] Mirror of https://github.com/Schniz/amqparty. making microservices fun with amqp
0

Configure Feed

Select the types of activity you want to include in your feed.

JavaScript 90.2%
Other 9.8%
9 1 0

Clone this repository

https://tangled.org/schlez.in/amqparty https://tangled.org/did:plc:3log7ko7dm7p5c7ij5pfdexg
git@tangled.org:schlez.in/amqparty git@tangled.org:did:plc:3log7ko7dm7p5c7ij5pfdexg

For self-hosted knots, clone URLs may differ based on your setup.



README.md

AMQParty#

All I wanted was to build a great microservices using RabbitMQ. but I can't understand all these terms... and all this boilerplate.. waaaa...

So lets party.

Installing#

npm install --save amqparty

Using#

const amqparty = require('amqparty');

// Just connect with the amqp library settings
amqparty.connect({ ...amqpProperties }).then(() => {
  console.log("Connected..");
  const send = amqparty.sender({ exchange: 'joe', name: 'userInfo' });

  send({
    some: 'data',
    iWould: 'like to send'
  }).then(data => {
    console.log('got myself: ', data);
  }).catch(err => {
    console.error('oh noes: ', err);
  });
});

Handling data in a service#

const { connect, handle } = require('amqparty');

const listen = () => {
  console.log("Started...");
  handle({
    exchange: 'joe',
    name: 'userInfo'
  }, (data, resolve, reject) => {
    // Do your thing here...
    resolve({
      heyYou: 'ohai'
    });
  });
};

connect({ ...amqProperties }).then(listen);

How it works#

sender#

  • creates a queue('joe', 'userInfo')
  • returns a function that:
    • generates a uuid
    • add a subscriber to the subscribers object:
      • will call the callback
      • unbind the queue
      • remove the subscriber from the subscribers object
    • binds the queue to userInfo.response.${uuid}
    • sends data

handle({ exchange: 'joe', name: 'userInfo' }, callback...)#

creates a queue (userInfo) that binds to userInfo.request