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

tim-azure-event-hubs

v0.0.2

Published

Azure Event Hubs SDK for Node.js

Downloads

7

Readme

azure-event-hubs

npm version

Usage

This library is primarily promise-based (for now, using Bluebird). See tests/sender_test.js or tests/receiver_test.js for some basic examples.

The simplest usage is to instantiate the main EventHubClient class with a ConnectionConfig, or use the static factory method EventHubClient.fromConnectionString(_connection-string_, _event-hub-path_). Once you have a client, you can use it to create senders and/or receivers using the client.createSender or client.createReceiver methods. Receivers emit message events when new messages come in, while senders have a simple send method that allows you to easily send messages (with an optional partition key).

Example 1 - Get the partition IDs.

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString('Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 'myeventhub')
client.getPartitionIds().then(function(ids) {
    ids.forEach(function(id) { console.log(id); });
});

Example 2 - Create a receiver

Creates a receiver on partition ID 10, for messages that come in after "now".

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString('Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 'myeventhub')
client.createReceiver('$Default', '10', { startAfterTime: Date.now() })
    .then(function (rx) {
        rx.on('errorReceived', function (err) { console.log(err); }); 
        rx.on('message', function (message) {
            var body = message.body;
            // @see eventdata.js
            var enqueuedTime = Date.parse(message.enqueuedTimeUtc);
        });
    });

Example 3 - Create a sender v1

Creates a sender, sends to a given partition "key" which is then hashed to a partition ID (so all messages with the same key will go to the same ID, but load is balanced between partitions).

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString('Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 'myeventhub')
client.createSender()
    .then(function (tx) {
        tx.on('errorReceived', function (err) { console.log(err); });
        tx.send({ contents: 'Here is some text sent to partition key my-pk.' }, 'my-pk'); 
    });

Example 4 - Create a sender v2

Creates a sender against a given partition ID (10). You should use send to a given partition key, but if you need to send to a given partition ID we'll let you do it.

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString('Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 'myeventhub')
client.createSender('10')
    .then(function (tx) {
        tx.on('errorReceived', function (err) { console.log(err); });
        tx.send({ contents: 'Here is some text sent to partition 10.' }); 
    });

Example 5 - Create a receiver with a custom policy

Creates a receiver for a given partition ID, with a larger max message size than the default (10000 bytes).

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString(
    'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 
    'myeventhub',
    { receiverLink: { attach: { maxMessageSize: 100000 }}});
client.createReceiver('$Default', '10', { startAfterTime: Date.now() })
    .then(function (rx) {
        rx.on('errorReceived', function (err) { console.log(err); }); 
        rx.on('message', function (message) {
            var body = message.body;
            var enqueuedTime = Date.parse(message.enqueuedTimeUtc);
        });
    });

Example 6 - Create a throttled receiver

Creates a receiver for a given partition ID, with a custom policy that throttles messages. Initially the client can deliver 10 messages, and after the "credit" goes below 5, the receiver will start allowing more messages only for those that have been "settled". Settling can be done via the settlement methods on EventData, such as accept or reject.

var EventHubClient = require('azure-event-hubs').Client;

var client = EventHubClient.fromConnectionString(
    'Endpoint=sb://my-servicebus-namespace.servicebus.windows.net/;SharedAccessKeyName=my-SA-name;SharedAccessKey=my-SA-key', 
    'myeventhub',
    EventHubClient.RenewOnSettle(10,5));
client.createReceiver('$Default', '10', { startAfterTime: Date.now() })
    .then(function (rx) {
        rx.on('errorReceived', function (err) { console.log(err); }); 
        rx.on('message', function (message) {
            var body = message.body;
            var enqueuedTime = Date.parse(message.enqueuedTimeUtc);
            // ... do some processing ...
            message.accept();
        });
    });