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

azure-queue-subscriber

v1.1.1

Published

A package for consuming messages from an Azure Queue

Downloads

92

Readme

azure-queue-subscriber

This package allows you to consume messages from an Azure Queue using Node.js.

Installation

To use this package, you can install it via npm:

npm install azure-queue-subscriber

Usage

First, require the package in your Node.js file:

const Consumer = require('azure-queue-subscriber');

The package provides a Consumer class that you can use to consume messages from a queue.

Constructor

const consumer = new Consumer(options);

The options parameter is an object that contains the following properties:

  • connectionString: The connection string for the Azure Storage account that contains the queue.
  • queueName: The name of the queue to consume messages from.
  • handleMessage: A callback function that will be called for each message received from the queue.
  • batchSize: (Optional) The number of messages to retrieve at a time. Defaults to 1.
  • pollDelaySeconds: (Optional) The number of seconds to wait between each poll of the queue. Defaults to 1.
  • maximumExecutionTimeSeconds: (Optional) The maximum amount of time (in seconds) that a message can be locked for processing. Defaults to 10.
  • authenticationErrorTimeoutSeconds: (Optional) The amount of time (in seconds) to wait before retrying after an authentication error. Defaults to 10.
  • queueService: (Optional) An instance of the QueueClient class from the @azure/storage-queue package. This is optional and can be used if you need more control over the queue service.
  • maximumRetries: (Optional) The total number of retries for failed jobs before they are deleted from the queue.
  • useLogtailLogger: (Optional) Whether to use Logtail for logging. Defaults to false.
  • logtailKey: (Optional) The Logtail API key. Required if useLogtailLogger is true.
  • loggerService: (Optional) An instance of the Logtail logger service. Required if useLogtailLogger is true.

Methods

start()

Starts the consumer, which begins polling the queue for messages.

consumer.start();

stop()

Stops the consumer.

consumer.stop();

Events

The Consumer class is an EventEmitter, which means that you can listen for events that are emitted by the class. The following events are available:

  • message_processed: Emitted when a message has been processed successfully. The message object is passed as the argument to the event listener.
  • processing_error: Emitted when there is an error processing a message. The error object and message object are passed as arguments to the event listener.
  • error: Emitted when there is an error that is not related to processing a message. The error object is passed as the argument to the event listener.
  • stopped: Emitted when the consumer has been stopped.
  • starting listening process: Emitted when the consumer is starting to listen to the queue for messages.
  • No messages available to be processed: Emitted when the queue is empty.

Logtail

To use Logtail as for external logging, please refer to the logtail documentation for detailed instructions on how to setup your logging console and key.

Example

Here's an example of how to use the Consumer class:

const Consumer = require('azure-queue-subscriber');

const consumer = new Consumer({
  connectionString: '<your-storage-account-connection-string>',
  queueName: '<your-queue-name>',
  handleMessage: async (message, done) => {
    console.log('Received message:', message.messageText);
    // Process message here
    done(); // Call done() to indicate that message processing is complete
  }
});

consumer.on('message_processed', (message) => {
  console.log('Message processed:', message.messageText);
});

consumer.on('processing_error', (err, message) => {
  console.error('Error processing message:', err, message.messageText);
});

consumer.on('error', (err) => {
  console.error('Error:', err);
});

consumer.start();

Credits

This node package is an adaptation of azure-queue-consumer