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

[event-hubs] add checkkpointing to migration guide sample #13016

Merged
4 commits merged into from
Dec 24, 2020
Merged
Changes from 2 commits
Commits
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
26 changes: 22 additions & 4 deletions sdk/eventhub/event-hubs/migrationguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ This and the need to support improvements to the algorithm used for managing par
Other noteworthy changes:

- The `send` method on the client that allowed sending single events in each call is removed
in favor of the `sendBatch` to encourage sending events in batches for better throughput.
in favor of the `sendBatch` to encourage sending events in batches for better throughput.
- The `sendBatch` method on the client has two overloads. One takes an array of events. The other takes an
object of type `EventDataBatch` that should be created using the `createBatch` method on the client. This object represents the batch and can be safely filled until the maximum size allowed.
object of type `EventDataBatch` that should be created using the `createBatch` method on the client. This object represents the batch and can be safely filled until the maximum size allowed.

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

Expand Down Expand Up @@ -257,7 +257,14 @@ const eph = EventProcessorHost.createFromConnectionString(
// In V2, you get a single event passed to your callback. If you had asynchronous code running in your callback,
// it is not awaited before the callback is called for the next event.
const onMessage = (context, event) => {
/** your code here **/
/** Your code to process the event here **/

try {
await context.checkpointFromEventData(event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might convey that we recommend checkpointing every event. Can we add some pretty words to clarify that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, though honestly I'm not sure what the recommended approach is given there's no backpressure in old EPH!

} catch (err) {
console.log(`Error when checkpointing on partition ${context.partitionId}: `, err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to show the catch, log, throw parts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose not 😄

throw err;
}
};

// This is your error handler for errors occuring when receiving events.
Expand Down Expand Up @@ -290,7 +297,18 @@ const subscription = eventHubConsumerClient.subscribe(partitionId, {
// If your callback is an async function or returns a promise, it will be awaited before the
// callback is called for the next batch of events.
processEvents: (events, context) => {
/** your code here **/
/** Your code to process events here **/

try {
// The events array could be empty, so only checkpoint if it contained events.
if (events.length) {
// save a checkpoint for the last event now that we've processed this batch.
await context.updateCheckpoint(events[events.length - 1]);
}
} catch (err) {
console.log(`Error when checkpointing on partition ${context.partitionId}: `, err);
throw err;
}
},

// Prior to V5, errors were handled by separate callbacks depending
Expand Down