public final class RabbitMqUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
buildExchangeName(net.roboconf.core.model.beans.Application application,
boolean dm)
Builds the exchange name for RabbitMQ.
|
static String |
buildExchangeName(String applicationName,
boolean dm)
Builds the exchange name for RabbitMQ.
|
static String |
buildRoutingKeyForAgent(net.roboconf.core.model.beans.Instance instance)
Builds the routing key for an agent.
|
static String |
buildRoutingKeyForAgent(String rootInstanceName)
Builds the routing key for an agent.
|
static void |
closeConnection(com.rabbitmq.client.Channel channel)
Closes the connection to a channel.
|
static void |
configureFactory(com.rabbitmq.client.ConnectionFactory factory,
String messageServerIp,
String messageServerUsername,
String messageServerPassword)
Configures the connection factory with the right settings.
|
static void |
declareApplicationExchanges(String applicationName,
com.rabbitmq.client.Channel channel)
Declares the required exchanges for an application.
|
static void |
listenToRabbitMq(String sourceName,
Logger logger,
com.rabbitmq.client.QueueingConsumer consumer,
LinkedBlockingQueue<Message> messages)
Listens to RabbitMQ messages.
|
public static String buildExchangeName(String applicationName, boolean dm)
applicationName - the application namedm - true if we want the exchange name for the DM, false for the agentspublic static String buildExchangeName(net.roboconf.core.model.beans.Application application, boolean dm)
application - an applicationdm - true if we want the exchange name for the DM, false for the agentspublic static String buildRoutingKeyForAgent(net.roboconf.core.model.beans.Instance instance)
instance - an instance managed by the agentpublic static String buildRoutingKeyForAgent(String rootInstanceName)
rootInstanceName - the name of the root instance associated with the agentpublic static void configureFactory(com.rabbitmq.client.ConnectionFactory factory,
String messageServerIp,
String messageServerUsername,
String messageServerPassword)
throws IOException
factory - the connection factorymessageServerIp - the message server IP (can contain a port and can but null too)messageServerUsername - the user name for the message servermessageServerPassword - the password for the message serverIOException - if something went wrongpublic static void closeConnection(com.rabbitmq.client.Channel channel)
throws IOException
channel - the channel to close (can be null)IOException - if something went wrongpublic static void declareApplicationExchanges(String applicationName, com.rabbitmq.client.Channel channel) throws IOException
Every time the DM or an agent must send a message, we must be sure all the exchanges have been declared. Otherwise, it will result in an error in the client. And this error will close the channel.
To PREVENT stupid errors, it is really important to declare both exchanges at once!
applicationName - the application namechannel - the RabbitMQ channelIOException - if an error occurspublic static void listenToRabbitMq(String sourceName, Logger logger, com.rabbitmq.client.QueueingConsumer consumer, LinkedBlockingQueue<Message> messages)
Be careful, this method aims at avoiding duplicate code. It starts an (almost) infinite loop and should be used with caution.
sourceName - the source name (DM, agent name...)logger - the loggerconsumer - the RabbitMQ consumermessages - the list where to store the received messagesCopyright © 2015. All rights reserved.