use of com.rabbitmq.client.ShutdownSignalException in project microservices by pwillhan.
the class Sender method waitForResponse.
public String waitForResponse(final String correlationId) {
QueueingConsumer consumer = new QueueingConsumer(channel);
String result = null;
try {
channel.basicConsume(RESPONSE_QUEUE, true, consumer);
QueueingConsumer.Delivery delivery = consumer.nextDelivery(3000);
String message = new String(delivery.getBody());
if (delivery.getProperties() != null) {
String msgCorrelationId = delivery.getProperties().getCorrelationId();
if (!correlationId.equals(msgCorrelationId)) {
LOGGER.warn("Received response of another request.");
} else {
result = message;
}
}
LOGGER.info("Message received: " + message);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
} catch (ShutdownSignalException e) {
LOGGER.error(e.getMessage(), e);
} catch (ConsumerCancelledException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
return result;
}
use of com.rabbitmq.client.ShutdownSignalException in project microservices by pwillhan.
the class CompetingReceiver method receive.
public String receive() {
if (channel == null) {
initialize();
}
String message = null;
try {
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
message = new String(delivery.getBody());
LOGGER.info("Message received: " + message);
return message;
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
} catch (ShutdownSignalException e) {
LOGGER.error(e.getMessage(), e);
} catch (ConsumerCancelledException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
}
return message;
}
use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.
the class ChannelLimitNegotiation method openingTooManyChannels.
@Test
public void openingTooManyChannels() throws Exception {
int n = 48;
Connection conn = null;
try {
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'");
ConnectionFactory cf = TestUtils.connectionFactory();
conn = cf.newConnection();
assertEquals(n, conn.getChannelMax());
for (int i = 1; i <= n; i++) {
assertNotNull(conn.createChannel(i));
}
// ChannelManager guards against channel.open being sent
assertNull(conn.createChannel(n + 1));
// Construct a channel directly
final ChannelN ch = new ChannelN(((AutorecoveringConnection) conn).getDelegate(), n + 1, new ConsumerWorkService(Executors.newSingleThreadExecutor(), Executors.defaultThreadFactory(), ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT));
conn.addShutdownListener(new ShutdownListener() {
public void shutdownCompleted(ShutdownSignalException cause) {
// make sure channel.open continuation is released
ch.processShutdownSignal(cause, true, true);
}
});
ch.open();
fail("expected channel.open to cause a connection exception");
} catch (IOException e) {
checkShutdownSignal(530, e);
} finally {
TestUtils.abort(conn);
Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'");
}
}
use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.
the class Bug19219Test method it.
@Test
public void it() throws IOException, InterruptedException {
final Consumer c = new DefaultConsumer(channel);
// each.
for (int i = 0; i < Q_COUNT; i++) {
String qName = channel.queueDeclare().getQueue();
channel.queueBind(qName, "amq.fanout", "");
channel.basicConsume(qName, false, c);
}
// 2. send lots of messages in background, to keep the server,
// and especially the queues, busy
final Runnable r = new Runnable() {
public void run() {
try {
startPublisher();
} catch (IOException e) {
} catch (InterruptedException e) {
} catch (TimeoutException e) {
e.printStackTrace();
}
}
};
for (int i = 0; i < PUB_THREAD_COUNT; i++) {
final Thread t = new Thread(r);
t.start();
// wait for thread to finish initialisation
init.acquire();
}
// tell all threads to resume
resume.countDown();
// wait for threads to get into full swing
Thread.sleep(CLOSE_DELAY);
// 3. close channel. This will result in the server notifying
// all the queues in parallel, which in turn will requeue all
// the messages. The combined workload may result in some
// notifications timing out.
boolean success = false;
try {
channel.abort();
success = true;
} catch (ShutdownSignalException e) {
} finally {
// We deliberately do not perform a clean shutdown of all
// the connections. This test is pushing the server really
// hard, so we chose the quickest way to end things.
channel = null;
connection = null;
assertTrue(success);
}
}
use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-java-client by rabbitmq.
the class QueueingConsumerTests method nThreadShutdown.
@Test
public void nThreadShutdown() throws Exception {
Channel channel = connection.createChannel();
final QueueingConsumer c = new QueueingConsumer(channel);
channel.queueDeclare(QUEUE, false, true, true, null);
channel.basicConsume(QUEUE, c);
final AtomicInteger count = new AtomicInteger(THREADS);
final CountDownLatch latch = new CountDownLatch(THREADS);
for (int i = 0; i < THREADS; i++) {
new Thread() {
@Override
public void run() {
try {
while (true) {
c.nextDelivery();
}
} catch (ShutdownSignalException sig) {
count.decrementAndGet();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
latch.countDown();
}
}
}.start();
}
connection.close();
// Far longer than this could reasonably take
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(0, count.get());
}
Aggregations