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] Updates APIs surrounding event processing and checkpointing #4994

Merged
merged 6 commits into from
Sep 5, 2019

Conversation

chradek
Copy link
Contributor

@chradek chradek commented Sep 4, 2019

This change:

  • Changes PartitionProcessor to be a class instead of an interface. This allows users to subclass PartitionProcessor so they only need to implement the methods they need.
  • Updates the EventProcessor to accept a PartitionProcessor class, instead of a factory that returns a PartitionProcessor.
  • Updates PartitionProcessor methods to each accept a PartitionContext. This way no parameters need to be passed to the PartitionProcessor constructor when the SDK instantiates it.
  • Removes CheckpointManager and moves updateCheckpoint into PartitionContext.
  • Removes the initialOffsetPosition from the EventProcessorOptions.
  • Updates readme/samples

@chradek
Copy link
Contributor Author

chradek commented Sep 4, 2019

/azp run js - eventhubs-client - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@chradek chradek marked this pull request as ready for review September 5, 2019 15:09
@chradek
Copy link
Contributor Author

chradek commented Sep 5, 2019

/azp run js - eventhubs-client - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

);
try {
// checkpoint using the last event in the batch
await this._checkpointManager.updateCheckpoint(events[events.length - 1]);
await partitionContext.updateCheckpoint(events[events.length - 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we checkpointing inside the for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I only looked at changing the API to use the new version, missed the fact that it was in the for loop this whole time. I'll update it.

async close() {
console.log(`Stopped processing`);
async close(reason: CloseReason, partitionContext: PartitionContext) {
console.log(`Stopped processing for reason ${reason}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this print out the reason in string or number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This prints out the reason as a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That said, I think we should probably change the CloseReason enum to a union of string literals. Then it's easy to get auto-completion, and clear that it's a string.

@@ -266,18 +193,18 @@ export class EventProcessor {
constructor(
consumerGroupName: string,
eventHubClient: EventHubClient,
partitionProcessorFactory: PartitionProcessorFactory,
PartitionProcessorClass: typeof PartitionProcessor,
Copy link
Contributor

Choose a reason for hiding this comment

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

To make this stand out more, do you think PartitionProcessorClassName would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as no one tries to put in the class name as a string :) What about PartitionProcessorConstructor? Or is that as confusing?

Copy link
Contributor

Choose a reason for hiding this comment

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

Meh, lets keep what you have for now.

* A checkpoint is meant to represent the last successfully processed event by the user from a particular
* partition of a consumer group in an Event Hub instance.
*
* When the `updateCheckpoint()` method on the `CheckpointManager` class is called by the user, a
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* When the `updateCheckpoint()` method on the `CheckpointManager` class is called by the user, a
* When the `updateCheckpoint()` method on the `PartitionContext` class is called by the user, a

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

}

/**
* `PartitionContext` holds information on the partition, consumer group and event hub
* being processed by the `EventProcessor`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* being processed by the `EventProcessor`.
* being processed by the `EventProcessor`. It also allows users to update checkpoints via the `updateCheckpoint` method

? eventDataOrSequenceNumber
: eventDataOrSequenceNumber.sequenceNumber,
offset:
typeof eventDataOrSequenceNumber === "number" ? offset! : eventDataOrSequenceNumber.offset,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
typeof eventDataOrSequenceNumber === "number" ? offset! : eventDataOrSequenceNumber.offset,
typeof offset=== "number" ? offset : eventDataOrSequenceNumber.offset,

@chradek chradek merged commit c8afde1 into Azure:master Sep 5, 2019
@chradek chradek deleted the event-processor-simpler branch September 5, 2019 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants