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

@vtfk/azure-servicebus-queue

v1.2.0

Published

High-level API for Azure Servicebus Queue operations

Downloads

5

Readme

(WIP) azure-servicebus-queue

High-level API for Azure Servicebus Queue operations.

Supports to send and receive messages >64kb by storing and retrieving from blob storage.

Uses the @azure/service-bus SDK

Install

npm i --save @vtfk/azure-servicebus-queue

API

Connection

Get connection string for Service Bus & names for Queues/Topics/Subscriptions

  • In the Azure Portal, go to Dashboard > Service Bus > your-servicebus-namespace.
  • Note down the "Primary Connection String" of RootManageSharedAccessKey at Shared access policies under Settings tab.
  • To work with Queues, find the "Queues" tab right under "Entities" at your-servicebus-namespace, create a Queue and note down its name.
  • To work with Topics, find the "Topics" tab right under "Entities" at your-servicebus-namespace, create a Topic. Go to your-servicebus-namespace > your-topic, create subscriptions for the topic. Note down the names of the topic and subscriptions.
const serviceBusClient = require('@vtfk/azure-servicebus-queue')({
  connectionString: '<Servicebus Connection String>'
  /* Uncomment to send and receive messages >64kb
    storageConnectionString: '<Blob Service SAS URL>'
    storageContainerName: '<Container name>'
  */
})

Service Bus operations

TODO

Subcription client operations

TODO

Topic operations

First, connect to the desired topic

const topic = serviceBusClient.topic('topicName')

Peek messages

Looks at mesages but don't delete

const limit = 6
const messages = await topic.peek(limit)

Returns an array of max 6 messages.

Peek messages by sequence number

const messages = await topic.peekBySequenceNumber('<sequenceNumber>')

Send message

const message = { body: 'message' }
await topic.send(message)

Receive message(s)

const limit = 10
const timeoutInSeconds = 1
const messages = await topic.receive(limit, timeoutInSeconds)

Send batch

const messages = [{ body: '1' }, { body: '2' }]
await topic.sendBatch(messages)

Schedule Message

const dateToSend = new Date().toISOString()
const message = { body: 'message' }
await topic.scheduleMessage(dateToSend, message)

Schedule Messages

const dateToSend = new Date().toISOString()
const messages = [{ body: '1' }, { body: '2' }]
await topic.scheduleMessages(dateToSend, messages)

Queue operations

First, connect to the desired queue

const queue = serviceBusClient.queue(queueName)

Peek messages

Looks at mesages but don't delete

const limit = 6
const messages = await queue.peek(limit)

Returns an array of max 6 messages.

Peek messages by sequence number

const messages = await queue.peekBySequenceNumber('<sequenceNumber>')

Send message

const message = { body: 'message' }
await queue.send(message)

Receive message(s)

const limit = 10
const timeoutInSeconds = 1
const messages = await queue.receive(limit, timeoutInSeconds)

Send batch

const messages = [{ body: '1' }, { body: '2' }]
await queue.sendBatch(messages)

Schedule Message

const dateToSend = new Date().toISOString()
const message = { body: 'message' }
await queue.scheduleMessage(dateToSend, message)

Schedule Messages

const dateToSend = new Date().toISOString()
const messages = [{ body: '1' }, { body: '2' }]
await queue.scheduleMessages(dateToSend, messages)

Storage operations

Inside storage you will find readBigMessage and sendBigMessage.
These will use the storageConnectionString and storageContainerName arguments to get the correct blob.

Send big messages

Store a message and get the ID in return.

const message = 'A message that is to big for the servicebus queue'
const fileId = await serviceBusClient.storage.sendBigMessage(message)

Read big messages

Reads a message from the configured blob storage with a specified ID.
Useful if a function binding is used for listening to new messages.

const fileId = '5266176d-dc5f-4304-b87e-5a4ef78a29b1.json'
const message = await serviceBusClient.storage.readBigMessage(fileId)

Returns the content of the blob with that ID.

Examples

See examples/example.js

To run example.js create file .env in project root with following content

QUEUE_NAME=<queue name>
QUEUE_CONNECTION_STRING=<Servicebus Connection String>
BLOB_SERVICE_SAS_URL=<Blob Service SAS URL> # Only needed for bigfile example
BLOB_CONTAINER_NAME=<Container name> # Only needed for bigfile example

And run npm run example or npm run example-bigfile (to test with messages >64kb)

License

MIT