1+ import { Broker } from '../model/broker.model'
2+ import { MessageListener } from '../model/message-listener.model'
13import { HandlerRegistry } from './handler-registry'
2- import { Broker , Connection } from '../model/broker.model '
4+ import { CommandListener } from './listeners/command-listener '
35import { EventListener } from './listeners/event-listener'
46import { QueryListener } from './listeners/query-listener'
7+ import { ReactiveCommonsContext } from './reactive-commons-context'
58
69export interface ReactiveCommonsConfiguration {
710 appName : string
@@ -14,17 +17,21 @@ export class ReactiveCommons {
1417 private config : ReactiveCommonsConfiguration
1518 ) { }
1619
17- start ( ) : Promise < Connection > {
20+ start ( ) : Promise < ReactiveCommonsContext > {
1821 const connection = this . broker . connect ( )
1922
20- const eventListener = new EventListener ( this . config , connection , this . registry )
21- const queryListener = new QueryListener ( this . config , connection , this . registry )
23+ const messageListeners : MessageListener [ ] = [
24+ new EventListener ( this . config , connection , this . registry ) ,
25+ new QueryListener ( this . config , connection , this . registry ) ,
26+ new CommandListener ( this . config , connection , this . registry )
27+ ]
2228
23- return Promise . all ( [
24- eventListener . setupResources ( ) ,
25- queryListener . setupResources ( ) ,
26- eventListener . startListening ( ) ,
27- queryListener . startListening ( )
28- ] ) . then ( ( ) => connection )
29+ const context = new ReactiveCommonsContext ( connection )
30+
31+ return Promise . all (
32+ messageListeners . map ( listener =>
33+ Promise . all ( [ listener . setupResources ( ) , listener . startListening ( ) ] )
34+ )
35+ ) . then ( ( ) => context )
2936 }
3037}
0 commit comments