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

Provide bus abstractions #11

Closed
RomanReznichenko opened this issue Mar 30, 2022 · 0 comments · Fixed by #12
Closed

Provide bus abstractions #11

RomanReznichenko opened this issue Mar 30, 2022 · 0 comments · Fixed by #12
Assignees
Labels
Type: enhancement New feature or request.

Comments

@RomanReznichenko
Copy link
Contributor

RomanReznichenko commented Mar 30, 2022

Abstractions that should be provided:

Command

Should be generic. Users should be able to provide message and response types.

export abstract class Command<T, R> {
  // ...
}

The Command can be executed in a way that is more approach you or convenient from the client's perspective.

await new Command<T, R>(/*parameters*/).execute(dispatcher);
await dispatcher.execute(await new Command<T, R>(/*parameters*/));

Event

Should be generic. Users should be able to provide message type. To get the Event publishing result users should register Handler.

export abstract class Event<T> {
  // ...
}

The Event can be executed in a way that is more approach you or convenient from the client's perspective.

await new Event <T>(/*parameters*/).publish(dispatcher);
await dispatcher.publish(await new Event<T>(/*parameters*/));

CommandDispatcher

Users can use CommandDispatcher to synchronously execute commands

export interface CommandDispatcher {
  execute<T, R>(command: Command<T, R>): Promise<R | undefined>;
}

EventDispatcher

Users can use EventDispatcher to asynchronously publish events

export interface EventDispatcher {
  publish<T>(event: Event<T>): Promise<void>;
}

Handler

Users can use Handler to handle events dispatched from the application

export interface Handler<T, R> {
  handle(argument: T): Promise<R>;
}

RetryStrategy

Users can be able to use retries in the case when the connection is lost

export interface RetryStrategy {
  acquire<T extends (...args: unknown[]) => unknown>(
    task: T
  ): Promise<ReturnType<T>>;
}

EventBus

Users can use EventBus to communicate between the service. EventBus should extend from EventDispatcher and CommandDispatcher

export interface EventBus extends EventDispatcher, CommandDispatcher {
  register<T extends Event<R>, R>(
    type: new (...args: unknown[]) => EventHandler<T>
  ): Promise<void>;

  unregister<T extends Event<R>, R>(
    type: new (...args: unknown[]) => EventHandler<T>
  ): Promise<void>;

  init?(): Promise<void>;
  destroy?(): Promise<void>;
}
@derevnjuk derevnjuk changed the title Provide abstractions to handle integration events and commands Provide bus abstractions Mar 30, 2022
@derevnjuk derevnjuk added the Type: enhancement New feature or request. label Mar 30, 2022
derevnjuk pushed a commit that referenced this issue Apr 5, 2022
derevnjuk added a commit that referenced this issue Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants