Skip to content
Snippets Groups Projects
Commit b4309528 authored by Peter Hooper's avatar Peter Hooper
Browse files

Move EventBus into its own file

parent fe560100
No related branches found
No related tags found
No related merge requests found
// Abstract Message Queue - types and interfaces
/**
* TODO: Once agreed, add these to DefinitelyTyped so they can be shared.
*/
export type EventType = string;
export interface Event<T extends object> {
readonly eventType: EventType;
readonly id: string; // Generated when the event is emitted
readonly created: Date;
readonly payload: T; // The actual data the event is carrying.
// version: has been removed - so we can remain weakly typed
// context: has also been removed - if you need information about the origin
// source of the event then put it in the payload.
}
export interface EventPublisher {
// Promise<boolean> should this become void | exception? we only need to know if something went wrong
publish<T extends object>(event: Event<T>): Promise<boolean>;
}
export interface EventSubscriber {
// handler: returns whether or not we should ack the message
subscribe<T extends object>(eventType: string, handler: (event: Event<T>) => Promise<boolean>): void;
}
export abstract class EventBus {
// register the following:
// - eventsToHandle - a list of events you will publish/subscribe to
// - serviceName - used when subscribing to generate a unique queue for holding
// incoming messages of the form: `consumer__${eventType}__${serviceName}`
constructor(readonly eventsToHandle: EventType[], readonly serviceName: string) {}
destroy(): Promise<void> {
return Promise.resolve();
}
}
// This isn't generic enough
export interface EventConfig {
url: string;
}
export * from './event-bus';
export * from './types';
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment