1616use Enqueue \Symfony \Client \DependencyInjection \ClientFactory ;
1717use Enqueue \Symfony \DependencyInjection \TransportFactory ;
1818use Enqueue \Symfony \DiUtils ;
19+ use Interop \Queue \Context ;
1920use Symfony \Component \Config \FileLocator ;
2021use Symfony \Component \Config \Resource \FileResource ;
2122use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -35,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container): void
3536
3637 // find default configuration
3738 $ defaultName = null ;
38- foreach ($ config as $ name => $ configs ) {
39+ foreach ($ config as $ name => $ modules ) {
3940 // set first as default
4041 if (null === $ defaultName ) {
4142 $ defaultName = $ name ;
@@ -49,40 +50,65 @@ public function load(array $configs, ContainerBuilder $container): void
4950
5051 $ transportNames = [];
5152 $ clientNames = [];
52- foreach ($ config as $ name => $ configs ) {
53+ foreach ($ config as $ name => $ modules ) {
5354 // transport & consumption
5455 $ transportNames [] = $ name ;
5556
56- $ transportFactory = (new TransportFactory ($ name ));
57- $ transportFactory ->buildConnectionFactory ($ container , $ configs ['transport ' ]);
57+ $ transportFactory = (new TransportFactory ($ name, $ defaultName === $ name ));
58+ $ transportFactory ->buildConnectionFactory ($ container , $ modules ['transport ' ]);
5859 $ transportFactory ->buildContext ($ container , []);
59- $ transportFactory ->buildQueueConsumer ($ container , $ configs ['consumption ' ]);
60+ $ transportFactory ->buildQueueConsumer ($ container , $ modules ['consumption ' ]);
6061 $ transportFactory ->buildRpcClient ($ container , []);
6162
6263 // client
63- if (isset ($ configs ['client ' ])) {
64+ if (isset ($ modules ['client ' ])) {
6465 $ clientNames [] = $ name ;
6566
66- $ clientConfig = $ configs ['client ' ];
67+ $ clientConfig = $ modules ['client ' ];
6768 // todo
68- $ clientConfig ['transport ' ] = $ configs ['transport ' ];
69- $ clientConfig ['consumption ' ] = $ configs ['consumption ' ];
69+ $ clientConfig ['transport ' ] = $ modules ['transport ' ];
70+ $ clientConfig ['consumption ' ] = $ modules ['consumption ' ];
7071
71- $ clientFactory = new ClientFactory ($ name );
72- $ clientFactory ->build ($ container , $ clientConfig, $ defaultName === $ name );
73- $ clientFactory ->createDriver ($ container , $ configs ['transport ' ]);
72+ $ clientFactory = new ClientFactory ($ name, $ defaultName === $ name );
73+ $ clientFactory ->build ($ container , $ clientConfig );
74+ $ clientFactory ->createDriver ($ container , $ modules ['transport ' ]);
7475 $ clientFactory ->createFlushSpoolProducerListener ($ container );
7576 }
7677
7778 // monitoring
78- if (isset ($ configs ['monitoring ' ])) {
79+ if (isset ($ modules ['monitoring ' ])) {
7980 $ monitoringFactory = new MonitoringFactory ($ name );
80- $ monitoringFactory ->buildStorage ($ container , $ configs ['monitoring ' ]);
81- $ monitoringFactory ->buildConsumerExtension ($ container , $ configs ['monitoring ' ]);
81+ $ monitoringFactory ->buildStorage ($ container , $ modules ['monitoring ' ]);
82+ $ monitoringFactory ->buildConsumerExtension ($ container , $ modules ['monitoring ' ]);
83+
84+ if (isset ($ modules ['client ' ])) {
85+ $ monitoringFactory ->buildClientExtension ($ container , $ modules ['monitoring ' ]);
86+ }
87+ }
88+
89+ // job-queue
90+ if (false == empty ($ modules ['job ' ]['enabled ' ])) {
91+ if (false === isset ($ modules ['client ' ])) {
92+ throw new \LogicException ('Client is required for job-queue. ' );
93+ }
8294
83- if (isset ( $ configs [ ' client ' ]) ) {
84- $ monitoringFactory -> buildClientExtension ( $ container , $ configs [ ' monitoring ' ] );
95+ if ($ name !== $ defaultName ) {
96+ throw new \ LogicException ( ' Job-queue supports only default configuration. ' );
8597 }
98+
99+ $ loader ->load ('job.yml ' );
100+ }
101+
102+ // async events
103+ if (false == empty ($ modules ['async_events ' ]['enabled ' ])) {
104+ if ($ name !== $ defaultName ) {
105+ throw new \LogicException ('Async events supports only default configuration. ' );
106+ }
107+
108+ $ extension = new AsyncEventDispatcherExtension ();
109+ $ extension ->load ([[
110+ 'context_service ' => Context::class,
111+ ]], $ container );
86112 }
87113 }
88114
@@ -112,25 +138,6 @@ public function load(array $configs, ContainerBuilder $container): void
112138 $ this ->loadDoctrineClearIdentityMapExtension ($ config , $ container );
113139 $ this ->loadSignalExtension ($ config , $ container );
114140 $ this ->loadReplyExtension ($ config , $ container );
115-
116- // if ($config['job']) {
117- // if (!class_exists(Job::class)) {
118- // throw new \LogicException('Seems "enqueue/job-queue" is not installed. Please fix this issue.');
119- // }
120- //
121- // $loader->load('job.yml');
122- // }
123- //
124- // if ($config['async_events']['enabled']) {
125- // if (false == class_exists(AsyncEventDispatcherExtension::class)) {
126- // throw new \LogicException('The "enqueue/async-event-dispatcher" package has to be installed.');
127- // }
128- //
129- // $extension = new AsyncEventDispatcherExtension();
130- // $extension->load([[
131- // 'context_service' => 'enqueue.transport.default.context',
132- // ]], $container);
133- // }
134141 }
135142
136143 public function getConfiguration (array $ config , ContainerBuilder $ container ): Configuration
0 commit comments