-
Notifications
You must be signed in to change notification settings - Fork 125
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
Dispatcher is not an event broker dependency #389
Dispatcher is not an event broker dependency #389
Conversation
Still pass it to PubSub::Broker. Just prepare to remove it from Broker.
@@ -1,15 +1,19 @@ | |||
require 'concurrent' | |||
|
|||
module RubyEventStore | |||
DEFAULT_DISPATCHER = PubSub::Dispatcher.new |
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 is constant :( please don't
class Client | ||
def initialize(repository:, | ||
mapper: Mappers::Default.new, | ||
event_broker: PubSub::Broker.new, | ||
event_broker: PubSub::Broker.new, |
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 is always a new, separate instance, initialized for every new client. no accidentally shared dependencies.
end | ||
|
||
def within(&block) | ||
raise ArgumentError if block.nil? | ||
Within.new(block, event_broker) | ||
Within.new(block, event_broker, dispatcher) |
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.
step in a good direction, i wonder if we could not pass self
instead of event_broker, dispatcher
.
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.
probably not.
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.
Nope. We do not have thread subscribers in client, we need a broker here (and dispatcher too). We might have get this from client but they are protected and exposing this outside client is not good.
@@ -4,12 +4,14 @@ class Client < RubyEventStore::Client | |||
|
|||
def initialize(repository: RailsEventStoreActiveRecord::EventRepository.new, | |||
mapper: RubyEventStore::Mappers::Default.new, | |||
event_broker: EventBroker.new(dispatcher: ActiveJobDispatcher.new), | |||
event_broker: EventBroker.new, |
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.
is Broker still actually a broker if it does not handle dispatching the events?
I know it was my idea, but I don't think I am particularly happy with the end result. I was not happy with broker taking dispatcher as a dependency. I am not so happy with client orchestrating the broker&dispatcher flows either. I think we are missing a 3rd option. I think we need a new class that takes Dispatcher and Broker as dependencies. And since broker no longer deals with dispatching, I believe it should be named differently. It's more like a... list of subscribers, list of handlers, ... handlers register, observers ? This new class would basically implement a pub/sub. I think the API would be that of current Broker. Hmmm, I think that basically means. Instead of doing all that we did here. Let's extract those 4 methods from Broker as a separate class (ie register). And broker (aka pub-sub) just wires these 2 dependencies together. class Client
def initialize(dispatcher:, register:, ...)
@broker = EventBroker.new(dispatcher, register)
end
What do you think? |
It makes sense. We will have 3 classes. Dispatcher - responsible for dispatching events to subscribers |
@mpraglowski exactly. I am not sure about the names though: Dispatcher - mkay I was even thinking about
😂 Feel free to come up with anything you feel good about. |
They will be always provided by Client.
no deprecations for this change? |
No description provided.