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

[Feature Request]: Expose Worker Events to Client Applications #427

Closed
filipeesch opened this issue Sep 12, 2023 · 0 comments
Closed

[Feature Request]: Expose Worker Events to Client Applications #427

filipeesch opened this issue Sep 12, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@filipeesch
Copy link
Member

filipeesch commented Sep 12, 2023

Is your request related to a problem you have?

The problem we're facing is the need to provide client applications with a way to monitor and react to internal worker events within the KafkaFlow framework. Currently, some consumers using asynchronous processing require knowledge of when a worker is stopping or has stopped to initiate important application shutdown processes, such as disposing of objects or storing state information in a database. However, the existing framework lacks a standardized way to expose these worker events to the client application, resulting in a potential complexity in managing these events. This problem can lead to message loss in cases where the application is terminated without proper cleanup.

Describe the solution you'd like

We advocate the incorporation of the Observer pattern within the KafkaFlow infrastructure. This will facilitate clients to keep tabs on KafkaFlow subjects and be alerted when specific intrinsic framework activities transpire.

Observer Pattern Implementation:

  1. ISubject & ISubjectObserver Interfaces: These form the core of the Observer pattern. ISubject lets observers subscribe to it, and ISubjectObserver defines how an observer reacts when notified.

  2. Subject<TSubject, TArg> Class: An abstract implementation which provides methods for subscription (Subscribe) and notification (NotifyAsync). This class is enhanced with a log handler to report potential issues during the notification process.

  3. VoidObject: A placeholder type used in contexts where an argument type needs to be provided, but the actual value is irrelevant. This ensures type safety while conveying that the object should be disregarded.

Example Usage:

Here's a rudimentary example of using WorkerStoppedSubject:

var workerStoppedSubject = new WorkerStoppedSubject(logHandlerInstance);

workerStoppedSubject.Subscribe(new YourObserverImplementation());

// Elsewhere in your code, when a worker stops:
await workerStoppedSubject.NotifyAsync(VoidObject.Value);
@filipeesch filipeesch added the enhancement New feature or request label Sep 12, 2023
@filipeesch filipeesch added this to the v3.0.0 milestone Sep 12, 2023
@filipeesch filipeesch self-assigned this Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants