/** * Access RabbitMQ object * @return singleton instance or null */ public static RabbitMQPublisher getInstance() { if (singleton == null) { RabbitMQPublisher publisher = new RabbitMQPublisher(); if (publisher.isConnected()) { singleton = publisher; } } return singleton; }
/** * Broadcast message using RabbitMQ * @param content of the message */ public static boolean broadcast(Object content) { RabbitMQPublisher rabbitMQ = RabbitMQPublisher.getInstance(); if (rabbitMQ != null) { return rabbitMQ.broadcast(content); } else { DispatchLogger.log("RabbitMQ is not properly configured, therefore it is not possible to publish any messages. Please consult logs and double check configuration files"); return false; } } }
/** * Publish message using RabbitMQ * @param content of the message * @param routing key */ public static boolean publish(Object content, String routing) { RabbitMQPublisher rabbitMQ = RabbitMQPublisher.getInstance(); if (rabbitMQ != null) { return rabbitMQ.publish(content, routing); } else { DispatchLogger.log("RabbitMQ is not properly configured, therefore it is not possible to publish any messages. Please consult logs and double check configuration files"); return false; } }
@Override public void run() { try { // check the database connection whether it is alive if (new DbAccess().ping()) logger.trace("Health check: Database connection is alive"); else throw new Exception("Database is down"); // test whether we have live TCP connection to RabbitMQ listener if (RabbitMQListener.getInstance().isConnected()) logger.trace("Health check: RabbitMQ Listener is alive"); else throw new Exception("RabbitMQ Listener is down"); // test our TCP connection to RabbitMQ Publisher if (RabbitMQPublisher.getInstance().isConnected()) logger.trace("Health check: RabbitMQ Publisher is alive"); else throw new Exception("RabbitMQ Publisher is down"); // we passed all the tests HealthStatus.getInstance().setHealthy(); } catch (Exception e) { logger.trace(String.format("Health check: failed (%s)", e.getMessage())); // we couldn't access the InfluxDB HealthStatus.getInstance().setUnhealthy(e.getMessage()); } } }
/** * Restore the microservice */ protected synchronized void setHealthy() { // if not already healthy if (!healthy) { healthy = true; reason = null; resetWatch(); // stop remaining scheduled checks TaskExecutor.getInstance().shutDown(); // try to start publisher if (RabbitMQPublisher.getInstance() == null) { healthy = false; } // try to start consumer if (!ConsumeManager.startConsumption()) { healthy = false; // shut down publisher RabbitMQPublisher.shutDown(); } // schedule micro service check scheduleCheck(); } }
/** * Publish a message to RabbitMQ * @param content to be send * @param routing key */ protected boolean publish(Object content, String routing) { return send(dispatchChannel, dispatchExchange, content, routing); }
/** * Shut down the singleton if it's running */ public static void shutDown() { if (singleton != null) { String msg = "Shutting down RabbitMQ Publisher"; logger.trace(msg); DispatchLogger.log(msg); singleton.stop(); singleton = null; } } }
@Override public void run() { logger.trace("We are shutting down the Rule Engine"); // and Consumer (RabbitMQ) ConsumeManager.stopConsumption(); // don't forget about Publisher (RabbitMQ) RabbitMQPublisher.shutDown(); // let's shut down rule manager RuleManagement.shutDown(); // do the same with Hibernate HibernateClient.shutDown(); } }
/** * Constructor has to be hidden */ private Messenger() { rabbitMQ = RabbitMQPublisher.getInstance(); }
public RabbitMQPublisher() { PublisherCredentials credentials = Loader.getSettings().getPublisherCredentials(); dispatchExchange = credentials.getPublisherDispatchExchange(); broadcastExchange = credentials.getPublisherBroadcastExchange(); establishConnection(credentials); }
/** * Broadcast message using RabbitM! * @param content of the message */ public boolean broadcast(Object content) { if (rabbitMQ != null) { return rabbitMQ.broadcast(content); } else { DispatchLogger.log("RabbitMQ is not properly configured, therefore it is not possible to publish any messages. Please consult logs and double check configuration files"); return false; } }
/** * Publish message using RabbitMQ * @param content of the message * @param routing key */ public boolean publish(Object content, String routing) { if (rabbitMQ != null) { return rabbitMQ.publish(content, routing); } else { DispatchLogger.log("RabbitMQ is not properly configured, therefore it is not possible to publish any messages. Please consult logs and double check configuration files"); return false; } }
@Override public void run() { try { // check the database connection whether it is alive if (new DbAccess().ping()) logger.trace("Health check: Database connection is alive"); else throw new Exception("Database is down"); // test whether we have live TCP connection to RabbitMQ listener if (RabbitMQListener.getInstance().isConnected()) logger.trace("Health check: RabbitMQ Listener is alive"); else throw new Exception("RabbitMQ Listener is down"); // test our TCP connection to RabbitMQ Publisher if (RabbitMQPublisher.getInstance().isConnected()) logger.trace("Health check: RabbitMQ Publisher is alive"); else throw new Exception("RabbitMQ Publisher is down"); // we passed all the tests HealthStatus.getInstance().setHealthy(); } catch (Exception e) { logger.trace(String.format("Health check: failed (%s)", e.getMessage())); // we couldn't access the InfluxDB HealthStatus.getInstance().setUnhealthy(e.getMessage()); } } }
/** * Restore the microservice */ protected synchronized void setHealthy() { // if not already healthy if (!healthy) { healthy = true; reason = null; resetWatch(); // stop remaining scheduled checks TaskExecutor.getInstance().shutDown(); // try to start publisher if (RabbitMQPublisher.getInstance() == null) { healthy = false; } // try to start consumer if (!ConsumeManager.startDataAndCommandProcessing()) { healthy = false; // shut down publisher RabbitMQPublisher.shutDown(); } // schedule micro service check scheduleCheck(); } }
/** * Broadcast a message to RabbitMQ * @param content to be send */ protected boolean broadcast(Object content) { return send(broadcastChannel, broadcastExchange, content, ""); }
/** * Shut down the singleton if it's running */ public static void shutDown() { if (singleton != null) { String msg = "Shutting down RabbitMQ Publisher"; logger.trace(msg); DispatchLogger.log(msg); singleton.stop(); singleton = null; } } }
@Override public void run() { logger.trace("We are shutting down Billing micro service"); // shut down executor service TaskExecutor.getInstance().forceShutDown(); // and Consumer (RabbitMQ) ConsumeManager.stopDataAndCommandProcessing(); // don't forget about Publisher (RabbitMQ) RabbitMQPublisher.shutDown(); // as well as db pool manager new DbAccess().shutDown(); } }
/** * Connect to RabbitMQ with Publisher and Consumer */ private static void checkAndSetupRabbitMQ() { // establish connections with RabbitMQ exchanges and queues if (RabbitMQPublisher.getInstance() == null) { String log = "Couldn't establish connection with RabbitMQ Publisher"; logger.error(log); System.err.println(log); System.exit(ERR_RABBITMQ); } if (!ConsumeManager.startDataAndCommandProcessing()) { String log = "Couldn't establish connection with RabbitMQ Consumer"; logger.error(log); System.err.println(log); System.exit(ERR_RABBITMQ); } outputProgressBar(); }
public RabbitMQPublisher() { PublisherCredentials credentials = Loader.getSettings().getPublisherCredentials(); dispatchExchange = credentials.getPublisherDispatchExchange(); broadcastExchange = credentials.getPublisherBroadcastExchange(); establishConnection(credentials); }
/** * Access RabbitMQ object * @return singleton instance or null */ public static RabbitMQPublisher getInstance() { if (singleton == null) { RabbitMQPublisher publisher = new RabbitMQPublisher(); if (publisher.isConnected()) { singleton = publisher; } } return singleton; }