Skip to content

Commit 2ad98da

Browse files
committed
CLOUDSTACK-6365: support virtual host and ssl in rabbitMQ event bus
with this fix, virtual host on the AMQP server can be specified. Also SSL can be used for connection between management server and AMQP servers.
1 parent 35b2bd5 commit 2ad98da

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus {
6060
private static String username;
6161
private static String password;
6262

63+
public static void setVirtualHost(String virtualHost) {
64+
RabbitMQEventBus.virtualHost = virtualHost;
65+
}
66+
67+
private static String virtualHost;
68+
69+
public static void setUseSsl(String useSsl) {
70+
RabbitMQEventBus.useSsl = useSsl;
71+
}
72+
73+
private static String useSsl;
74+
6375
// AMQP exchange name where all CloudStack events will be published
6476
private static String amqpExchangeName;
6577

@@ -104,6 +116,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
104116
throw new ConfigurationException("Unable to get the port details of AMQP server");
105117
}
106118

119+
if (useSsl != null && !useSsl.isEmpty()) {
120+
if (!useSsl.equalsIgnoreCase("true") && !useSsl.equalsIgnoreCase("false")) {
121+
throw new ConfigurationException("Invalid configuration parameter for 'ssl'.");
122+
}
123+
}
124+
107125
if (retryInterval == null) {
108126
retryInterval = 10000;// default to 10s to try out reconnect
109127
}
@@ -345,9 +363,18 @@ private synchronized Connection createConnection() throws Exception {
345363
ConnectionFactory factory = new ConnectionFactory();
346364
factory.setUsername(username);
347365
factory.setPassword(password);
348-
factory.setVirtualHost("/");
349366
factory.setHost(amqpHost);
350367
factory.setPort(port);
368+
369+
if (virtualHost != null && !virtualHost.isEmpty()) {
370+
factory.setVirtualHost(virtualHost);
371+
} else {
372+
factory.setVirtualHost("/");
373+
}
374+
375+
if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
376+
factory.useSslProtocol();
377+
}
351378
Connection connection = factory.newConnection();
352379
connection.addShutdownListener(disconnectHandler);
353380
s_connection = connection;

0 commit comments

Comments
 (0)