Search in sources :

Example 21 with ShutdownSignalException

use of com.rabbitmq.client.ShutdownSignalException in project airavata by apache.

the class RabbitMQPublisher method connect.

private void connect() throws AiravataException {
    try {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri(properties.getBrokerUrl());
        connectionFactory.setAutomaticRecoveryEnabled(properties.isAutoRecoveryEnable());
        connection = connectionFactory.newConnection();
        connection.addShutdownListener(new ShutdownListener() {

            public void shutdownCompleted(ShutdownSignalException cause) {
            }
        });
        log.info("connected to rabbitmq: " + connection + " for " + properties.getExchangeName());
        channel = connection.createChannel();
        if (properties.getPrefetchCount() > 0) {
            channel.basicQos(properties.getPrefetchCount());
        }
        if (properties.getExchangeName() != null) {
            channel.exchangeDeclare(properties.getExchangeName(), properties.getExchangeType(), // durable
            true);
        }
    } catch (Exception e) {
        String msg = "RabbitMQ connection issue for exchange : " + properties.getExchangeName();
        log.error(msg);
        throw new AiravataException(msg, e);
    }
}
Also used : ShutdownListener(com.rabbitmq.client.ShutdownListener) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) AiravataException(org.apache.airavata.common.exception.AiravataException) AiravataException(org.apache.airavata.common.exception.AiravataException)

Example 22 with ShutdownSignalException

use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.

the class QueueingConsumerTests method consumerCancellationInterruptsQueuingConsumerWait.

@Test
public void consumerCancellationInterruptsQueuingConsumerWait() throws IOException, InterruptedException {
    String queue = "cancel_notification_queue_for_queueing_consumer";
    final BlockingQueue<Boolean> result = new ArrayBlockingQueue<Boolean>(1);
    channel.queueDeclare(queue, false, true, false, null);
    final QueueingConsumer consumer = new QueueingConsumer(channel);
    Runnable receiver = new Runnable() {

        public void run() {
            try {
                try {
                    consumer.nextDelivery();
                } catch (ConsumerCancelledException e) {
                    result.put(true);
                    return;
                } catch (ShutdownSignalException e) {
                } catch (InterruptedException e) {
                }
                result.put(false);
            } catch (InterruptedException e) {
                fail();
            }
        }
    };
    Thread t = new Thread(receiver);
    t.start();
    channel.basicConsume(queue, consumer);
    channel.queueDelete(queue);
    assertTrue(result.take());
    t.join();
}
Also used : ConsumerCancelledException(com.rabbitmq.client.ConsumerCancelledException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) QueueingConsumer(com.rabbitmq.client.QueueingConsumer) Test(org.junit.Test)

Example 23 with ShutdownSignalException

use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.

the class ShutdownNotifierComponent method notifyListeners.

@Override
public void notifyListeners() {
    ShutdownSignalException sse = null;
    ShutdownListener[] sdls = null;
    synchronized (this.monitor) {
        sdls = this.shutdownListeners.toArray(new ShutdownListener[this.shutdownListeners.size()]);
        sse = this.shutdownCause;
    }
    for (ShutdownListener l : sdls) {
        try {
            l.shutdownCompleted(sse);
        } catch (Exception e) {
        // FIXME: proper logging
        }
    }
}
Also used : ShutdownListener(com.rabbitmq.client.ShutdownListener) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException)

Example 24 with ShutdownSignalException

use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.

the class JsonRpcClient method call.

/**
 * Public API - builds, encodes and sends a JSON-RPC request, and
 * waits for the response.
 *
 * @return the result contained within the reply, if no exception is found
 * @throws JsonRpcException if the reply object contained an exception
 * @throws TimeoutException if a response is not received within the timeout specified, if any
 */
public Object call(String method, Object[] params) throws IOException, JsonRpcException, TimeoutException {
    Map<String, Object> request = new HashMap<String, Object>();
    request.put("id", null);
    request.put("method", method);
    request.put("version", ServiceDescription.JSON_RPC_VERSION);
    params = (params == null) ? new Object[0] : params;
    request.put("params", params);
    String requestStr = mapper.write(request);
    try {
        String replyStr = this.stringCall(requestStr);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Reply string: {}", replyStr);
        }
        Class<?> expectedType;
        if ("system.describe".equals(method) && params.length == 0) {
            expectedType = Map.class;
        } else {
            ProcedureDescription proc = serviceDescription.getProcedure(method, params.length);
            expectedType = proc.getReturnType();
        }
        JsonRpcMapper.JsonRpcResponse reply = mapper.parse(replyStr, expectedType);
        return checkReply(reply);
    } catch (ShutdownSignalException ex) {
        // wrap, re-throw
        throw new IOException(ex.getMessage());
    }
}
Also used : ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) HashMap(java.util.HashMap) IOException(java.io.IOException)

Aggregations

ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)24 IOException (java.io.IOException)20 ConsumerCancelledException (com.rabbitmq.client.ConsumerCancelledException)12 QueueingConsumer (com.rabbitmq.client.QueueingConsumer)12 Channel (com.rabbitmq.client.Channel)5 Connection (com.rabbitmq.client.Connection)4 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)4 ShutdownListener (com.rabbitmq.client.ShutdownListener)4 TimeoutException (java.util.concurrent.TimeoutException)4 Test (org.junit.Test)4 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)3 AMQP (com.rabbitmq.client.AMQP)2 RMQJMSSelectorException (com.rabbitmq.jms.util.RMQJMSSelectorException)2 IllegalStateException (javax.jms.IllegalStateException)2 InvalidSelectorException (javax.jms.InvalidSelectorException)2 JMSException (javax.jms.JMSException)2 BasicProperties (com.rabbitmq.client.AMQP.BasicProperties)1 Consumer (com.rabbitmq.client.Consumer)1 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)1 GetResponse (com.rabbitmq.client.GetResponse)1