2
I have this code right below that makes a connection to my server.
I would like to perform a status check of my server through a method that connects to that server, how can I implement this?
public class ConnectionRabbitmqFactoryConsumer {
private static final Logger LOGGER =
SaveLog.lauchLog(ReadConfigDatabase.class.getName());
public static ConnectionFactory getConnection() {
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("192.168.120.150");
factory.setUsername("adm");
factory.setPassword("adm");
factory.setPort(5672);
return factory;
} catch (Exception e) {
e.printStackTrace(System.err);
LOGGER.error("error conection rabbitmq ");
}
return null;
}
}
This is an application that performs sending message from my server / client. The code below prepares the sending of this message, before sending it falls into this getConnection(), to see if everything is ok with my server.
@Override
public void run() {
try {
//Execultar tarefas assincronas
ExecutorService threader = Executors.newFixedThreadPool(20);
Connection connection = ConnectionRabbitmqFactoryConsumer.getConnection().newConnection(threader);
.......
You want a method to check if the server is online then?
– Dherik
That, exactly.
– Ivan