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

Introduce interface for topic event subscriber #661

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

mfcollins3
Copy link
Contributor

@mfcollins3 mfcollins3 commented Dec 9, 2024

Description

I introduced the TopicEventSubscriber interface and added an AddTopicEventSubscriber method to the Server interface. TopicEventSubscriber will allow more complex subscribers to be registered that are using structs so that dependencies like sql.DB objects or other parameters can be provided to subscribers and used to process incoming events.

I modified TopicRegistrar to register and store TopicEventSubscriber instead of TopicEventHandler in the TopicRegistration struct. I created an adapter for TopicEventHandlerso that it implements the newTopicEventSubscriber` interface and can continue to be used without modification.

  • I introduced the TopicEventSubscriber type instead of rewriting the TopicEventHandler type to not break existing code. I used the pattern that net/http uses for Handler and HandlerFunc.
  • I did not define any new tests, but I modified the existing tests to work. Given the way that I changed TopicRegistration and making TopicEventHandler implement TopicEventSubscriber, I didn't think that any additional tests were necessary.

Issue reference

Please reference the issue this PR will close: #660

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

I introduced the TopicEventSubscriber interface to allow for
subscribers to be implemented as structs. This will allow subscribers
to be initialized with any settings or dependencies needed to process
incoming events.

I converted TopicEventHandler to implement TopicEventSubscriber. I
revised TopicRegistrar to store TopicEventSubscribers instead of
TopicEventHandlers.

Resolves dapr#660

Signed-off-by: Michael Collins <[email protected]>
@mfcollins3 mfcollins3 force-pushed the 660-subscriber-interface branch from c3b2d46 to d310732 Compare December 9, 2024 03:43
I added examples of how to use the TopicEventSubscriber interface to
create a new subscriber for both HTTP and gRPC services.

Signed-off-by: Michael Collins <[email protected]>
@mfcollins3 mfcollins3 changed the title [WIP] Introduce interface for topic event subscriber Introduce interface for topic event subscriber Dec 9, 2024
@mfcollins3 mfcollins3 marked this pull request as ready for review December 9, 2024 03:54
@mfcollins3 mfcollins3 requested review from a team as code owners December 9, 2024 03:54
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 61.56%. Comparing base (6c59092) to head (2528b25).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
service/http/topic.go 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
- Coverage   62.52%   61.56%   -0.96%     
==========================================
  Files          56       58       +2     
  Lines        4139     4296     +157     
==========================================
+ Hits         2588     2645      +57     
- Misses       1425     1521      +96     
- Partials      126      130       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mikeee mikeee left a comment

Choose a reason for hiding this comment

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

lgtm

@yaron2 yaron2 merged commit 31346f0 into dapr:main Dec 9, 2024
18 of 19 checks passed
@yaron2
Copy link
Member

yaron2 commented Dec 9, 2024

Thanks for your contribution!

@mfcollins3 mfcollins3 deleted the 660-subscriber-interface branch December 9, 2024 16:56
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.

Topic subscriptions should accept interfaces instead of functions
3 participants