Skip to content

Instantly share code, notes, and snippets.

View ramya-rao-a's full-sized avatar

Ramya Rao ramya-rao-a

View GitHub Profile
@ramya-rao-a
ramya-rao-a / event-hubs.js
Last active October 11, 2019 03:07
Event Hubs library proposal with single client
/*
This proposal builds on top of what was shipped in Preview 4 of Event Hubs library
and attempts to discard a separate notion of EPH by rolling that feature into the
existing concept of a "consumer".
This is mainly geared towards JS and can be tweaked for Python
This needs serious naming re-considerations for the methods on the consumer :)
*/
const client = new EventHubClient(connectionString, eventHubName);
@ramya-rao-a
ramya-rao-a / event-hubs-with-separate-clients.js
Last active October 10, 2019 01:25
Event Hubs library proposal where sender and receiver have their own clients
/*
Key changes:
- A dedicated "client" for EPH, making this a EventHubConsumerClient that customers would first gravitate towards
- start() & stop() would be top level methods
- In .Net, there would be 4 settable callbacks. These would be in the builder for Java.
- For Python & JS, these would be passable to the start() method
- State management is done via the PartitionContext that gets passed to the callbacks.
- .Net & Java will have to allow users to extend the base class to store the state
- This results in a dedicated client for send for symmetry, and so EventHubProducerClient
- send() & createBatch() would be top level methods, no need to create producers and maintain them
@ramya-rao-a
ramya-rao-a / EventProcessor-JS-proposal.js
Last active September 24, 2019 18:27
Proposal for Event Processor in JS
// User class extending the base class provided by the library
class SamplePartitionProcessor extends PartitionProcessor {
async processEvents(events) { console.log(events);}
async processError(error) { console.log(error); }
async initialize() { console.log(`Started processing partition: ${this.partitionId}`); }
async close(reason) { console.log(`Stopped processing partition: ${this.partitionId} for reason ${reason}`); }
}
// 3 constructor overloads similar to EventHubClient, extra arguments are consumerGroupName, and PartitionProcessor
// Options are not shown, but are similar to what EventHubClientOptions support + max batch size, max wait time per batch
@ramya-rao-a
ramya-rao-a / EventProcessorNetAPI.cs
Last active September 18, 2019 18:57
EP .Net API
/*
There are 3 players in this game.
- EventProcessor
- Provided by the sdk.
- Ideal Usage: Multiple instances on separate machines to balance partition load
- PartitionProcessor
- Abstract class provided by the sdk, meant to be extended by user where they provide code to process events
- Ideal Usage:
- Extended by user & passed to EventProcessor constructor via a factory in .Net & Java,
via the type/class name in JS & Python

Proposed API design for EPH in Typescript

// Name to be changed
export class EventProcessor {
  constructor(
    consumerGroupName: string,
    eventHubClient: EventHubClient,
// Main EventHubClient class
export class EventHubClient {
// Expects connectionString with EntityPath set to event hub name
constructor(connectionString: string, options?: EventHubClientOptions);
// Expects user implemented token provider. Token is used for auth over cbs link
constructor(host: string, entityPath: string, tokenProvider: TokenProvider, options?: EventHubClientOptions);
// Expects user to use @azure/ms-rest-nodeauth library to create the credentials
package main
import (
"context"
"fmt"
"time"
servicebus "github.com/Azure/azure-service-bus-go"
)
@ramya-rao-a
ramya-rao-a / deferred_receiveAndDelete_mode.js
Last active April 29, 2019 06:29
Sample JS code to illustrate issue with deferred msgs received in ReceiveAndDelete mode
/*
Set up instructions:
- Ensure you have Nodejs installed, else install from https://nodejs.org/en/
- Copy the this file to an empty folder
- Run `npm install @azure/service-bus` in this empty folder
- Add your connection string and partitioned queue (no sessions) details in the sample (use empty queue)
- Run `node deferred_receiveAndDelete_mode.js` (if you have named the file differently, use that name)
- Change the queue to other variations (unparitioned, sessions etc) and see the difference
*/
@ramya-rao-a
ramya-rao-a / deferred_receiveAndDelete_mode.go
Last active April 29, 2019 06:31
Sample Go code to illustrate issue with deferred msgs received in ReceiveAndDelete mode
/*
Set up instructions:
- Ensure you have Go installed, else install from https://golang.org/dl/
- Create a new folder and copy this file
- In that folder run `go mod init sbtests`
- Add your connection string and queue (no sessions) details
- Run `go run deferred_receiveAndDelete_mode.go` (if you have named the file differently, use that name)
*/
package main