-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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); | ||
} catch (err) { | ||
console.log(`Error when checkpointing on partition ${context.partitionId}: `, err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have to show the catch, log, throw parts? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!