Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventHubs migration guide (start) #2

Closed
wants to merge 37 commits into from
Closed
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
29858fe
starting the migration guide
richardpark-msft Dec 4, 2019
45065e3
Update event hubs migration guide.md
richardpark-msft Dec 5, 2019
a1c6ebd
Change wording to 'receiving'
richardpark-msft Dec 6, 2019
e7b1def
AAD line
richardpark-msft Dec 6, 2019
7ca4971
* Checked against code - casing for AAD was incorrect (should have be…
richardpark-msft Dec 6, 2019
c1855a0
Merge branch 'richardpark-eh-migration-guide' of https://github.com/r…
richardpark-msft Dec 6, 2019
5d7dceb
Applying Ramya's changes
richardpark-msft Dec 6, 2019
686dc6a
Took part of a description from our REST documentation and tailored i…
richardpark-msft Dec 6, 2019
e6e89bd
Merge branch 'richardpark-eh-migration-guide' of https://github.com/r…
richardpark-msft Dec 6, 2019
8edaf44
Updating migration guide sample for sending.
richardpark-msft Dec 6, 2019
52bce99
Add in a description of EventProcessorHost
richardpark-msft Dec 6, 2019
79fdac1
Removed the 'as well'
richardpark-msft Dec 6, 2019
a46af7a
Unlink dependencies if tests fail (#6483)
mikeharder Dec 10, 2019
1ff3be6
[Storage] Add more tests covering progress events (#6428)
jeremymeng Dec 10, 2019
3a81099
[event-hubs] Better error handling and reporting (#6465)
richardpark-msft Dec 10, 2019
94b5d23
[Core-http] Move getDefaultProxySettings into proxyPolicy (#6478)
jeremymeng Dec 10, 2019
27d9cb1
[core-amqp] adds support for idle timeout and additional logging (#6492)
chradek Dec 10, 2019
887e83a
[event-hubs] Updating samples folder to make it a standalone project …
richardpark-msft Dec 10, 2019
39f6a44
Adding example for EventProcessorHost => EventHubConsumerClient migra…
richardpark-msft Dec 10, 2019
339ba8c
* Don't use $Default anywhere if we can avoid it. Guide the user choo…
richardpark-msft Dec 10, 2019
7fe7dea
There were two packages, not one.
richardpark-msft Dec 11, 2019
20492ab
Document the multiple types of message receiving we can handle.
richardpark-msft Dec 11, 2019
78138d4
We only construct clients, not empires.
richardpark-msft Dec 11, 2019
8992aee
It's a function. Be proud of it and call it theoretically in the table.
richardpark-msft Dec 11, 2019
58bdcb1
Parens.
richardpark-msft Dec 11, 2019
07fb17c
Removed!
richardpark-msft Dec 11, 2019
b6286da
Updated with in-person feedback
Dec 11, 2019
de2de90
Remove backtick from the toc links
Dec 11, 2019
55e8480
send example was incorrect (should have been sendBatch)
Dec 11, 2019
de034b9
The user is in control of the batch size...
richardpark-msft Dec 11, 2019
93e8259
Merge branch 'richardpark-eh-migration-guide' of https://github.com/r…
Dec 11, 2019
8e74f24
Let's assume they're already full events and not just data.
richardpark-msft Dec 11, 2019
bb92f68
Tenatitively fixing sample
Dec 11, 2019
9b37716
Merge branch 'richardpark-eh-migration-guide' of https://github.com/r…
Dec 11, 2019
2c25e0e
Merge remote-tracking branch 'upstream/master' into richardpark-eh-mi…
Dec 11, 2019
96d7a5b
Advertise the goodness that was EPH and that is now part of the Event…
richardpark-msft Dec 11, 2019
0db9b43
* Make sample a bit more interesting by allowing them to specify the …
richardpark-msft Dec 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions event hubs migration guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Migration Guide (EventHubs 2 to 5)

## Class changes
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved

`EventHubClient` has been split into two clients - `EventHubProducerClient` (for sending
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
messages) and `EventHubConsumerClient` (for receiving messages).

| In v2 | Equivalent in v5 | Sample |
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
|------------------------------------------------|------------------------------------------------------------------|--------|
| `EventHubClient.createFromConnectionString` | `new EventHubProducerClient()` or `new EventHubConsumerClient()` | [All](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/) |
| `EventHubClient.createFromAadTokenCredentials` | `new EventHubProducerClient()` or `new EventHubConsumerClient()` | [usingAadAuth](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/usingAadAuth.ts)
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
| `EventHubClient.receive` | `EventHubConsumerClient.subscribe` | [receiveEvents](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/receiveEvents.ts) |
| `EventHubClient.receiveBatch` | Removed in favor of `EventHubConsumerClient.subscribe` | [receiveEvents](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/receiveEvents.ts) |
| `EventHubClient.send` | `EventHubConsumerClient.sendBatch` | [sendEvents](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/sendEvents.ts) |

### Migrating code from `EventHubClient` to `EventHubConsumerClient` for receiving events
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved

In V2, event handlers were passed as positional arguments to `receive`.

In V5, event handlers are passed as part of a `SubscriptionEventHandlers` shaped object.

For example, this code which receives from a partition in V2:

```typescript
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
const client = EventHubClient.createFromConnectionString(connectionString);
const rcvHandler = client.receive(partitionId, onMessageHandler, onErrorHandler, {
eventPosition: EventPosition.fromStart(),
consumerGroup: "$Default"
});
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
await rcvHandler.stop();
```

Becomes this in V5:

```typescript
const eventHubConsumerClient = new EventHubConsumerClient("$Default", connectionString);

const subscription = eventHubConsumerClient.subscribe(
partitionId, {
processInitialize: (initContext) => {
initContext.setStartingPosition(EventPosition.fromStart());
},
processEvents: onMessageHandler,
processError: onErrorHandler
});

await subscription.close();
```

See [`receiveEvents.ts`](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/samples/receiveEvents.ts)
for a sample program demonstrating this.

### Migrating code from `EventHubClient` to `EventHubProducerClient` for sending events

In V2, there were multiple options on how to send data.
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved

In V5, this has been consolidated into a more efficient `sendBatch` method.
Batching merges information from multiple messages into a single send, reducing
the amount of network communication needed vs sending messages one at a time.

So in V2:
```typescript
const client = EventHubClient.createFromConnectionString(connectionString);
console.log(`Sending event: ${eventData.body}`);
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
await client.send(eventData, partitionId);
richardpark-msft marked this conversation as resolved.
Show resolved Hide resolved
```

In V5:
```typescript
const eventHubProducerClient = new EventHubProducerClient(connectionString);
console.log(`Sending event: ${eventData.body}`);

// note that the partition ID is now specified as part of the
// batch, rather than as part of the sendBatch call.
const batch = await eventHubProducerClient.createBatch({
partitionId: partitionId
});

const added = batch.tryAdd(eventData);

if (!added) {
throw new Error("Failed to add event - larger than maximum allowed size");
}

await eventHubProducerClient.sendBatch(batch);
```