Example usage for com.rabbitmq.client ShutdownSignalException getReason

List of usage examples for com.rabbitmq.client ShutdownSignalException getReason

Introduction

In this page you can find the example usage for com.rabbitmq.client ShutdownSignalException getReason.

Prototype

public Method getReason() 

Source Link

Usage

From source file:org.teksme.server.common.messaging.AMQPBrokerManager.java

License:Apache License

public void shutdownCompleted(ShutdownSignalException sse) {

    Connection conn = (Connection) sse.getReference();
    Command closeCommand = (Command) sse.getReason();
    if (sse.isHardError()) {
        if (!sse.isInitiatedByApplication()) {
            AMQP.Connection.Close closeMethod = (AMQP.Connection.Close) closeCommand.getMethod();
            logger.log(Level.SEVERE, "Connection host [" + conn.getHost() + "] closed. Shutdown reason: "
                    + closeMethod.getReplyCode());
        }/*from ww  w  .  j  ava2  s.  c  o  m*/
    } else {
        Channel ch = (Channel) sse.getReference();
        logger.info("Connection host [" + conn.getHost() + "] closed. Shutdown reason: " + ch.getCloseReason());
    }

    logger.info("RabbitMQ AMQP broker shutdown completed!");

}

From source file:ss.udapi.sdk.services.RabbitMqConsumer.java

License:Apache License

@Override
public void handleShutdownSignal(String cTag, ShutdownSignalException signal) {

    if (connectShutDownLogged == false) {
        connectShutDownLogged = true; // so we don't end up logging it for
        // each cTag

        String hardError = "";
        String applInit = "";
        String reason = "";

        if (signal.isHardError()) {
            hardError = "connection";
        } else {//from  w  w  w . j a  v  a2s .c  om
            hardError = "channel";
        }

        if (signal.isInitiatedByApplication()) {
            applInit = "application";
        } else {
            applInit = "broker";
        }

        reason = signal.getReason().toString();
        logger.error("Connectivity to MQ has failed.  It was caused by " + applInit + " at the " + hardError
                + " level.  Reason received " + reason);
    }
    String resourceId = CtagResourceMap.getResource(cTag);
    ResourceImpl resource = (ResourceImpl) ResourceWorkerMap.getResourceImpl(resourceId);
    resource.mqDisconnectEvent();
    MQListener.removeMapping(cTag);
}

From source file:uk.trainwatch.rabbitmq.RabbitRPCClient.java

License:Apache License

private byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
        throws IOException, ShutdownSignalException, TimeoutException {
    checkConsumer();//  w  ww .  j  a v  a 2  s  . c o m
    BlockingCell<Object> k = new BlockingCell<>();

    String replyId = RabbitMQ.newCorrelationId();
    props = ((props == null) ? new AMQP.BasicProperties.Builder() : props.builder()).correlationId(replyId)
            .replyTo(replyQueue).build();
    continuationMap.put(replyId, k);

    publish(props, message);

    Object reply = k.uninterruptibleGet(timeout);
    if (reply instanceof ShutdownSignalException) {
        ShutdownSignalException sig = (ShutdownSignalException) reply;
        ShutdownSignalException wrapper = new ShutdownSignalException(sig.isHardError(),
                sig.isInitiatedByApplication(), sig.getReason(), sig.getReference());
        wrapper.initCause(sig);
        throw wrapper;
    } else {
        return (byte[]) reply;
    }
}

From source file:vn.com.uet.performance.rabbitmq.MulticastParams.java

License:Open Source License

private static boolean exists(Connection connection, Checker checker) throws IOException {
    try {//  w  w  w. jav  a2 s  .  co  m
        Channel ch = connection.createChannel();
        checker.check(ch);
        ch.abort();
        return true;
    } catch (IOException e) {
        ShutdownSignalException sse = (ShutdownSignalException) e.getCause();
        if (!sse.isHardError()) {
            AMQP.Channel.Close closeMethod = (AMQP.Channel.Close) sse.getReason();
            if (closeMethod.getReplyCode() == AMQP.NOT_FOUND) {
                return false;
            }
        }
        throw e;
    }
}