88namespace  Magento \MagentoCloud \Config ;
99
1010use  Magento \MagentoCloud \Config \Stage \DeployInterface ;
11+ use  Magento \MagentoCloud \Package \UndefinedPackageException ;
12+ use  Magento \MagentoCloud \Service \ActiveMq ;
1113use  Magento \MagentoCloud \Service \RabbitMq ;
1214use  Magento \MagentoCloud \Package \MagentoVersion ;
1315
1618 */ 
1719class  Amqp
1820{
21+     /** 
22+      * @var ActiveMq 
23+      */ 
24+     private  ActiveMq   $ activeMQ ;
25+ 
1926    /** 
2027     * @var RabbitMq 
2128     */ 
22-     private  $ rabbitMQ ;
29+     private  RabbitMq   $ rabbitMQ ;
2330
2431    /** 
2532     * @var DeployInterface 
2633     */ 
27-     private  $ stageConfig ;
34+     private  DeployInterface   $ stageConfig ;
2835
2936    /** 
3037     * @var ConfigMerger 
3138     */ 
32-     private  $ configMerger ;
39+     private  ConfigMerger   $ configMerger ;
3340
3441    /** 
3542     * @var MagentoVersion 
3643     */ 
37-     private  $ magentoVersion ;
44+     private  MagentoVersion   $ magentoVersion ;
3845
3946    /** 
40-      * @param RabbitMq $rabbitMQ 
47+      * @param ActiveMq        $activeMQ 
48+      * @param RabbitMq        $rabbitMQ 
4149     * @param DeployInterface $stageConfig 
42-      * @param ConfigMerger $configMerger 
43-      * @param MagentoVersion $magentoVersion 
50+      * @param ConfigMerger     $configMerger 
51+      * @param MagentoVersion   $magentoVersion 
4452     */ 
4553    public  function  __construct (
54+         ActiveMq   $ activeMQ ,
4655        RabbitMq   $ rabbitMQ ,
4756        DeployInterface   $ stageConfig ,
4857        ConfigMerger   $ configMerger ,
4958        MagentoVersion   $ magentoVersion
5059    ) {
60+         $ this  ->activeMQ  = $ activeMQ ;
5161        $ this  ->rabbitMQ  = $ rabbitMQ ;
5262        $ this  ->stageConfig  = $ stageConfig ;
5363        $ this  ->configMerger  = $ configMerger ;
@@ -58,7 +68,7 @@ public function __construct(
5868     * Returns queue configuration 
5969     * 
6070     * @return array 
61-      * @throws \Magento\MagentoCloud\Package\ UndefinedPackageException 
71+      * @throws UndefinedPackageException|ConfigException  
6272     */ 
6373    public  function  getConfig (): array 
6474    {
@@ -77,6 +87,7 @@ public function getConfig(): array
7787     * Returns merged queue configuration 
7888     * 
7989     * @return array 
90+      * @throws ConfigException 
8091     */ 
8192    private  function  getMergedConfig (): array 
8293    {
@@ -96,19 +107,34 @@ private function getMergedConfig(): array
96107
97108    /** 
98109     * Convert amqp service configuration to magento format. 
110+      * Prioritizes ActiveMQ first, then falls back to RabbitMQ. 
99111     * 
100112     * @return array 
101113     */ 
102114    private  function  getAmqpConfig (): array 
103115    {
116+         // First priority: ActiveMQ 
117+         if  ($ amqpConfig  = $ this  ->activeMQ ->getConfiguration ()) {
118+             return  [
119+                 'amqp '  => [
120+                     'host '  => $ amqpConfig ['host ' ],
121+                     'port '  => $ amqpConfig ['port ' ],
122+                     'user '  => $ amqpConfig ['username ' ] ?? $ amqpConfig ['user ' ] ?? '' ,
123+                     'password '  => $ amqpConfig ['password ' ],
124+                     'virtualhost '  => $ amqpConfig ['vhost ' ] ?? '/ ' ,
125+                 ]
126+             ];
127+         }
128+ 
129+         // Fallback: RabbitMQ 
104130        if  ($ amqpConfig  = $ this  ->rabbitMQ ->getConfiguration ()) {
105131            return  [
106132                'amqp '  => [
107133                    'host '  => $ amqpConfig ['host ' ],
108134                    'port '  => $ amqpConfig ['port ' ],
109135                    'user '  => $ amqpConfig ['username ' ],
110136                    'password '  => $ amqpConfig ['password ' ],
111-                     'virtualhost '  => isset ( $ amqpConfig ['vhost ' ]) ?  $ amqpConfig [ ' vhost ' ] :  '/ ' ,
137+                     'virtualhost '  => $ amqpConfig ['vhost ' ] ??  '/ ' ,
112138                ]
113139            ];
114140        }
0 commit comments