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

Configurable Event Bus support #10

Closed
reypader opened this issue Apr 23, 2018 · 2 comments · Fixed by #12
Closed

Configurable Event Bus support #10

reypader opened this issue Apr 23, 2018 · 2 comments · Fixed by #12

Comments

@reypader
Copy link

reypader commented Apr 23, 2018

I was wondering how the team envisioned a configurable event bus that can delegate to an external pub/sub and queueing mechanism like AMQP, Amazon SQS/SNS, Google Cloud Pub/Sub (I believe it's queued internally).

I was planning to just extend the event bus and override certain methods. However, I believe if we can instead allow injection of a publisher/subscriber in the event bus, it would allow users to do as they please on the event handling.

export class EventBus extends ObservableBus<IEvent> implements IEventBus {
    publish<T extends IEvent>(event: T) {
            if(this.eventPublisher){
                ...publish to external queue...
            } else {
                this.subject$.next(event);
            }
    }

    bind<T extends IEvent>(handler: IEventHandler<IEvent>, name: string) {
            const stream$ = name ? this.ofEventName(name) : this.subject$;
            stream$.subscribe(event => handler.handle(event));
            
            if(this.eventSubscriber){
                ...subscribe a worker to the external queue...
                ...once a message is consumed call "this.subject$.next(event);"...
            }
    }
}

Instead of the clunky if-else blocks, we can have a "DefaultPublisher" and "DefaultSubscriber" that immediately consumes a published messaged and thus, immediately triggering this.subject$.next(event) similar to how it is right now.

Any thoughts?

@reypader
Copy link
Author

reypader commented Apr 25, 2018

I'm currently testing some changes for this on my fork but when I tried using it in the example, I'm getting the error Error: Cannot find module 'multer'.

This is after I tried installing @types/node on nest-cqrs since running npm run compile fails due to

node_modules/@nestjs/common/interfaces/external/multer-options.interface.d.ts(1,23): error TS2688: Cannot find type definition file for 'node'.
node_modules/@nestjs/common/interfaces/external/multer-options.interface.d.ts(46,17): error TS2304: Cannot find name 'Buffer'.

It's actually the first time I've tried using local typescript modules; always been a leecher. Any tips on how you guys test this locally?

@kamilmysliwiec
Copy link
Member

Let's track this feature in your pull request: #12

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 a pull request may close this issue.

2 participants