@@ -18,6 +18,7 @@ class Amqp
18
18
const CONFIG_PATH_PASSWORD = 'queue/amqp/password ' ;
19
19
const DEFAULT_MANAGEMENT_PROTOCOL = 'http ' ;
20
20
const DEFAULT_MANAGEMENT_PORT = '15672 ' ;
21
+ const DEFAULT_VIRTUALHOST = '/ ' ;
21
22
22
23
/**
23
24
* @var Curl
@@ -36,6 +37,13 @@ class Amqp
36
37
*/
37
38
private $ host ;
38
39
40
+ /**
41
+ * RabbitMQ virtual host
42
+ *
43
+ * @var string
44
+ */
45
+ private $ virtualHost ;
46
+
39
47
/**
40
48
* Initialize dependencies.
41
49
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
@@ -59,6 +67,7 @@ public function __construct(
59
67
$ this ->deploymentConfig ->get (self ::CONFIG_PATH_HOST ),
60
68
defined ('RABBITMQ_MANAGEMENT_PORT ' ) ? RABBITMQ_MANAGEMENT_PORT : self ::DEFAULT_MANAGEMENT_PORT
61
69
);
70
+ $ this ->virtualHost = defined ('RABBITMQ_VIRTUALHOST ' ) ? RABBITMQ_VIRTUALHOST : self ::DEFAULT_VIRTUALHOST ;
62
71
}
63
72
64
73
/**
@@ -82,7 +91,7 @@ public function isAvailable(): bool
82
91
*/
83
92
public function getExchanges ()
84
93
{
85
- $ this ->curl ->get ($ this ->host . 'exchanges ' );
94
+ $ this ->curl ->get ($ this ->host . 'exchanges/ ' . urlencode ( $ this -> virtualHost ) );
86
95
$ data = $ this ->curl ->getBody ();
87
96
$ data = json_decode ($ data , true );
88
97
$ output = [];
@@ -100,7 +109,7 @@ public function getExchanges()
100
109
*/
101
110
public function getExchangeBindings ($ name )
102
111
{
103
- $ this ->curl ->get ($ this ->host . 'exchanges/%2f / ' . $ name . '/bindings/source ' );
112
+ $ this ->curl ->get ($ this ->host . 'exchanges/ ' . urlencode ( $ this -> virtualHost ) . ' / ' . $ name . '/bindings/source ' );
104
113
$ data = $ this ->curl ->getBody ();
105
114
return json_decode ($ data , true );
106
115
}
@@ -112,7 +121,7 @@ public function getExchangeBindings($name)
112
121
*/
113
122
public function getConnections ()
114
123
{
115
- $ this ->curl ->get ($ this ->host . 'connections ' );
124
+ $ this ->curl ->get ($ this ->host . 'vhosts/ ' . urlencode ( $ this -> virtualHost ) . ' / connections ' );
116
125
$ data = $ this ->curl ->getBody ();
117
126
$ data = json_decode ($ data , true );
118
127
$ output = [];
@@ -137,7 +146,9 @@ public function clearQueue(string $name, int $numMessages = 50)
137
146
"encoding " => "auto " ,
138
147
"truncate " => 50000
139
148
];
140
- $ this ->curl ->post ($ this ->host . 'queue/%2f/ ' . $ name . '/get ' , json_encode ($ body ));
149
+ $ this ->curl ->post (
150
+ $ this ->host . 'queue/ ' . urlencode ($ this ->virtualHost ) . '/ ' . $ name . '/get ' , json_encode ($ body )
151
+ );
141
152
return $ this ->curl ->getBody ();
142
153
}
143
154
0 commit comments