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

Subscribing to events using Subscriber should be a one-liner #34

Open
cer opened this issue Nov 19, 2016 · 3 comments
Open

Subscribing to events using Subscriber should be a one-liner #34

cer opened this issue Nov 19, 2016 · 3 comments
Assignees

Comments

@cer
Copy link
Collaborator

cer commented Nov 19, 2016

The developer should not need to write this.

const subscriber = new Subscriber({ subscriptions, logger });

subscriber.subscribe().forEach(subscription => {
  //Create EventDispatcher instance
  const dispatcher = new EventDispatcher({ getEventHandler, subscription, logger });
  dispatcher.run(subscription);

});
@cer
Copy link
Collaborator Author

cer commented Nov 19, 2016

One problem with this design is that the events being handled have no relationship with the events being subscribed to

const subscriptions = [
  {
    subscriberId: 'todo-list-todoAggregate',
    entityTypesAndEvents: todoEntityTypesAndEvents <<<===
  },
  {

vs.

Whatever getEventHandler knows how to process.

getEventHandler should tell Subscriber what to subscribe to.

@cer
Copy link
Collaborator Author

cer commented Nov 23, 2016

@dartvandru @dartandrevinsky

One possibility is an event handler looks like this:

export const eventHandlers = {
 [TodoAggregate] : {
   [todoCreatedEvent] : handleTodoCreatedEvent,
   [todoDeletedEvent] : handleTodoDeletedEvent,
   [todoUpdatedEvent] : handleTodoUpdatedEvent,
   [todoDeletionRequestedEvent]: handleTodoDeletionRequestedEvent
 }
};

In other words its a nested map: aggregate -> aggregateEvent -> eventHandler

The high-level subscription API looks something like this:

const subscriber = new Subscriber(eventuateClient);  // Rename -> SubscriptionManager?

// Do this one or more times:

subscriber.subscribe(eventHandlers)

@cer
Copy link
Collaborator Author

cer commented Feb 17, 2017

@dartvandru
I think the subscription API is still not quite right

  const dispatcher = new EventDispatcher({ eventHandlers: todoBulkDeleteAggregateEventHandlers });
  const subscriber = new SubscriptionManager({ eventuateClient, dispatcher });
  subscriber.subscribe({ subscriberId: 'todo-list-todoBulkDeleteAggregate', eventHandlers: todoBulkDeleteAggregateEventHandlers });

It should really be something like this.
First, create a global SubscriptionManager:

const subscriptionManager = new EventuateSubscriptionManager({ eventuateClient });

And then call subscribe() one or more times.

subscriptionManager.subscribe({ subscriberId: 'todo-list-todoBulkDeleteAggregate', 
                                   eventHandlers: todoBulkDeleteAggregateEventHandlers });

Internally, subscribe() can create a EventDispatcher etc but that should not be part of the API.

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

No branches or pull requests

2 participants