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);
}
}
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();
}
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
}
}
}
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());
}
}
Aggregations