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

@xiaojing0/amqpclient

v1.1.0

Published

manager client for rabbit mq

Downloads

6

Readme

node_rabbitmq_client

This is the node client of rabbitmq. Before using this client, you must confirm:

  1. rabbitmq is correctly installed in the current environment;
  2. ES6 and above are required.

Installation

npm i @xiaojing0/amqpclient

Example

const amqpclient = require('@xiaojing0/amqpclient');
amqpclient.init('amqp://localhost?heartbeat=60', {isDebugMode: true, prefetch: 100});

// work task queue
amqpclient.receiveWorkTask('workQueueName', function (msg) {
    console.log(msg); // print: 'hi!!!'
});
amqpclient.sendWorkTask('workQueueName', 'hi!!!')

// rpc task queue
amqpclient.receiveRpcRequest('rpcQueueName', function (msg) {
    console.log(msg); // print: 'your name?'
    return 'rpc server!';
});
amqpclient.sendRpcRequest('rpcQueueName', 'your name?')
    .then((result) => {
        console.log(result); // print: 'rpc server!'
    });

Usage

First, we need to init a connection:

const amqpclient = require('@xiaojing0/amqpclient');
amqpclient.init('amqp://localhost?heartbeat=60', {isDebugMode: true, prefetch: 100});
  • The initialization method receives two parameters, connectHost and configParams:
connectHost: 'amqp://localhost?heartbeat=60' // Message queue connection address

// [optional] Message queue config params
configParams: Object

// [optional] default to false, if set to true will show all AMQP logs
configParams.isDebugMode: Boolean,

 // [optional] default to 0 (no limit), This parameter limits the number of concurrent processing by the client in a unit of time.
configParams.prefetch: Number,

Note: The process of establishing a connection is completely asynchronous. You don't have to worry about requests that cannot be sent and answered during the connection establishment process. Because the client has a caching mechanism inside, all requests will be executed after the connection is established.

Send and receive a work task:

amqpclient.receiveWorkTask(workQueueName, consumeMethod, optionalParams);
amqpclient.sendWorkTask(workQueueName, taskData, optionalParams)
  • The receiveWorkTask method params:
workQueueName: String, // Work queue name, must be unique

consumeMethod: Function, // A consumption method for a work task, which is used to receive a message that processes a task queue

 // [optional] The config params of work queue 
optionalParams: Object,

 // [optional] Queue config parameter, default to {durable: true}, support all queue configuration parameters
optionalParams.queueOpts: Object,

 // [optional] consume config parameter, default to {noAck: false}, support all message configuration parameters
optionalParams.consumeOpts: Object,
  • The sendWorkTask method params:
workQueueName: String, // Work queue name, must be unique

taskData: String, // Task data must be String type


 // [optional] The config params of work queue 
optionalParams: Object,

 // [optional] Queue config parameter, default to {durable: true}, support all queue configuration parameters
optionalParams.queueOpts: Object,

 // [optional] message config parameter, default to {persistent: true}, support all message configuration parameters
optionalParams.msgOpts: Object,

Send and receive RPC:

amqpclient.receiveRpcRequest(rpcQueueName, consumeMethod);

const result = await amqpclient.sendRpcRequest(rpcQueueName, rpcData);
  • The receiveRpcRequest method params:
rpcQueueName: String, // rpc queue name, must be unique

consumeMethod: Function, // A consumption method for a rpc task, which is used to receive a message that processes a rpc queue
  • The sendRpcRequest method params:
rpcQueueName: String, // rpc queue name, must be unique

rpcData: String, // Task data must be String type

Note: The data returned by the rpc request is a serialized character type. If the returned result is an object, the type needs to be deserialized.

Tests

npm test

Contributing

Contributors