Socket
Socket
Sign inDemoInstall

rhea-promise

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rhea-promise

A Promisified layer over rhea AMQP client


Version published
Maintainers
4
Created

What is rhea-promise?

The rhea-promise npm package is a promise-based wrapper around the rhea library, which is an AMQP 1.0 client for Node.js. It simplifies the process of working with AMQP 1.0 by providing a more modern, promise-based API.

What are rhea-promise's main functionalities?

Sending Messages

This feature allows you to send messages to an AMQP 1.0 broker. The code sample demonstrates how to establish a connection, create a sender, send a message, and then close the sender and connection.

const { Connection, Sender } = require('rhea-promise');

async function sendMessage() {
  const connection = new Connection({ host: 'localhost', port: 5672 });
  await connection.open();
  const sender = await connection.createSender({ target: { address: 'queue' } });
  await sender.send({ body: 'Hello, World!' });
  await sender.close();
  await connection.close();
}

sendMessage().catch(console.error);

Receiving Messages

This feature allows you to receive messages from an AMQP 1.0 broker. The code sample demonstrates how to establish a connection, create a receiver, and handle incoming messages.

const { Connection, Receiver } = require('rhea-promise');

async function receiveMessages() {
  const connection = new Connection({ host: 'localhost', port: 5672 });
  await connection.open();
  const receiver = await connection.createReceiver({ source: { address: 'queue' } });
  receiver.on('message', (context) => {
    console.log('Received message:', context.message.body);
  });
}

receiveMessages().catch(console.error);

Request-Response Pattern

This feature allows you to implement a request-response pattern using AMQP 1.0. The code sample demonstrates how to send a request message and handle the response.

const { Connection, Sender, Receiver } = require('rhea-promise');

async function requestResponse() {
  const connection = new Connection({ host: 'localhost', port: 5672 });
  await connection.open();
  const sender = await connection.createSender({ target: { address: 'request_queue' } });
  const receiver = await connection.createReceiver({ source: { address: 'response_queue' } });

  receiver.on('message', (context) => {
    console.log('Received response:', context.message.body);
  });

  await sender.send({ body: 'Request message' });
}

requestResponse().catch(console.error);

Other packages similar to rhea-promise

Keywords

FAQs

Package last updated on 25 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc