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

@simplecomercio/rabbitmq-rpc

v1.3.2

Published

This custom npm module exports several functions that can be used to interact with a RabbitMQ server using the Remote Procedure Call (RPC) pattern and the AMQP protocol (Advanced Message Queuing Protocol).

Downloads

9

Readme

This custom npm module exports several functions that can be used to interact with a RabbitMQ server using the Remote Procedure Call (RPC) pattern and the AMQP protocol (Advanced Message Queuing Protocol).

This module allows for communication between different applications or services through the use of queues and message routing. It uses the AMQP protocol and the amqplib library to connect to a RabbitMQ server and send and receive messages.

Main function:

connect(uri:string): Promise<IRPCService>: This function connects to a RabbitMQ server using the provided URI and returns an object that contains several methods that can be used to interact with the server.

The IRPCService object contains the following methods:

getStatus(): Promise<Boolean>: which returns true if the channel is initialized and connected to the server, otherwise false.

publishToQueue(queueName: string, data: any): Promise<RPCResponse>: which sends a message to a specific queue.

createRouter(): Router: which creates a new router object that can be used to route messages to different queues.

The Router object contains the following methods:

route(queueName: string, cb: (obj: any) => void): which sets up a route to listen for messages on a queue. It takes a queueName string and a callback function as inputs. The queueName is the name of the queue on which to listen for messages, and the callback function is called for each message received. The callback function takes an argument obj which is the content of the message

Here's an example of how to use it:


import { connect, rpc } from '@simplecomercio/rabbitmq-rpc';

const rpcService = await connect('amqp://localhost:5672');
const isConnected = await rpc.getStatus();

if (isConnected)
	console.log('RabbitMQ Server connection is up');

To route messages to different queues, you can use the createRouter method to create a new router object and the route method to define the routing rules.


const router = rpc.createRouter();

router.route('queue-name', (obj: any) => {
	const { name: string } = obj
	const greetings = `Hello ${name}`
	return {
		status: 200,
		details: 'success',
		data: greetings
	}
});

You could then use the publishToQueue method to send a message to a specific queue.


const { status, details, data: greetings } = await rpcService.publishToQueue('queue-name', { name: 'Juan' });
console.log(greetings); // Hello Juan