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

Dispatcher is not an event broker dependency #389

Conversation

mpraglowski
Copy link
Member

No description provided.

@mpraglowski mpraglowski requested a review from paneq June 30, 2018 22:44
@@ -1,15 +1,19 @@
require 'concurrent'

module RubyEventStore
DEFAULT_DISPATCHER = PubSub::Dispatcher.new
Copy link
Member

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,
Copy link
Member

@paneq paneq Jul 1, 2018

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)
Copy link
Member

@paneq paneq Jul 1, 2018

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.

Copy link
Member

Choose a reason for hiding this comment

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

probably not.

Copy link
Member Author

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,
Copy link
Member

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?

@paneq
Copy link
Member

paneq commented Jul 1, 2018

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
  • dispatcher - knows how to call sync/async/whatever handlers that subscribed/registered for certain events
  • register - keeps a querable list of who subscribed for what.
  • broker - a facade for both. A full pub/sub implementation. Might even be called PubSub :)

What do you think?

@mpraglowski
Copy link
Member Author

It makes sense. We will have 3 classes.

Dispatcher - responsible for dispatching events to subscribers
Subscriber - responsible for managing subscriptions
Broker - "just" a pub sub - this will have both 2 previous ones given as dependency and will do the notifications - the code from client to notify subscribers should go there

@paneq
Copy link
Member

paneq commented Jul 2, 2018

@mpraglowski exactly.

I am not sure about the names though:

Dispatcher - mkay
Subscriber - is it really a subscriber? We call a subscriber the thing that subscribes (handlers), not the thing that keeps a list of subscriptions.
Broker - mkay

I was even thinking about

  • pub
  • sub
  • PubSub.new(pub, sub)

😂

Feel free to come up with anything you feel good about.

@mostlyobvious
Copy link
Member

no deprecations for this change?

@mostlyobvious mostlyobvious merged commit d69a2f8 into RailsEventStore:master Jul 6, 2018
@mpraglowski mpraglowski deleted the dispatcher-is-not-an-event-broker-dependency branch July 6, 2018 11:01
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.

3 participants