use of com.rabbitmq.client.ShutdownSignalException in project wso2-axis2-transports by wso2.
the class RabbitMQRPCMessageSender method processResponse.
private RabbitMQMessage processResponse(String correlationID) throws IOException {
QueueingConsumer consumer = dualChannel.getConsumer();
QueueingConsumer.Delivery delivery = null;
RabbitMQMessage message = new RabbitMQMessage();
String replyToQueue = dualChannel.getReplyToQueue();
String queueAutoDeclareStr = epProperties.get(RabbitMQConstants.QUEUE_AUTODECLARE);
boolean queueAutoDeclare = true;
if (!StringUtils.isEmpty(queueAutoDeclareStr)) {
queueAutoDeclare = Boolean.parseBoolean(queueAutoDeclareStr);
}
if (queueAutoDeclare && !RabbitMQUtils.isQueueAvailable(dualChannel.getChannel(), replyToQueue)) {
log.info("Reply-to queue : " + replyToQueue + " not available, hence creating a new one");
RabbitMQUtils.declareQueue(dualChannel, replyToQueue, epProperties);
}
int timeout = RabbitMQConstants.DEFAULT_REPLY_TO_TIMEOUT;
String timeoutStr = epProperties.get(RabbitMQConstants.REPLY_TO_TIMEOUT);
if (!StringUtils.isEmpty(timeoutStr)) {
try {
timeout = Integer.parseInt(timeoutStr);
} catch (NumberFormatException e) {
log.warn("Number format error in reading replyto timeout value. Proceeding with default value (30000ms)", e);
}
}
try {
if (log.isDebugEnabled()) {
log.debug("Waiting for delivery from reply to queue " + replyToQueue + " corr id : " + correlationID);
}
delivery = consumer.nextDelivery(timeout);
if (delivery != null) {
if (!StringUtils.isEmpty(delivery.getProperties().getCorrelationId())) {
if (delivery.getProperties().getCorrelationId().equals(correlationID)) {
if (log.isDebugEnabled()) {
log.debug("Found matching response with correlation ID : " + correlationID + ".");
}
} else {
log.error("Response not queued in " + replyToQueue + " for correlation ID : " + correlationID);
return null;
}
}
} else {
log.error("Response not queued in " + replyToQueue);
}
} catch (ShutdownSignalException e) {
log.error("Error receiving message from RabbitMQ broker " + e.getLocalizedMessage());
} catch (InterruptedException e) {
log.error("Error receiving message from RabbitMQ broker " + e.getLocalizedMessage());
} catch (ConsumerCancelledException e) {
log.error("Error receiving message from RabbitMQ broker" + e.getLocalizedMessage());
}
if (delivery != null) {
log.debug("Processing response from reply-to queue");
AMQP.BasicProperties properties = delivery.getProperties();
Map<String, Object> headers = properties.getHeaders();
message.setBody(delivery.getBody());
message.setDeliveryTag(delivery.getEnvelope().getDeliveryTag());
message.setReplyTo(properties.getReplyTo());
message.setMessageId(properties.getMessageId());
// get content type from message
String contentType = properties.getContentType();
if (contentType == null) {
// if not get content type from transport parameter
contentType = epProperties.get(RabbitMQConstants.REPLY_TO_CONTENT_TYPE);
if (contentType == null) {
// if none is given, set to default content type
log.warn("Setting default content type " + RabbitMQConstants.DEFAULT_CONTENT_TYPE);
contentType = RabbitMQConstants.DEFAULT_CONTENT_TYPE;
}
}
message.setContentType(contentType);
message.setContentEncoding(properties.getContentEncoding());
message.setCorrelationId(properties.getCorrelationId());
if (headers != null) {
message.setHeaders(headers);
if (headers.get(RabbitMQConstants.SOAP_ACTION) != null) {
message.setSoapAction(headers.get(RabbitMQConstants.SOAP_ACTION).toString());
}
}
}
return message;
}
use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-jms-client by rabbitmq.
the class RMQSession method getBrowsingChannel.
/**
* Get a (new) channel for queue browsing.
* @return channel for browsing queues
* @throws JMSException if channel not available
*/
Channel getBrowsingChannel() throws JMSException {
try {
synchronized (this.bcLock) {
// not transactional
Channel chan = this.getConnection().createRabbitChannel(false);
this.browsingChannels.add(chan);
return chan;
}
} catch (Exception e) {
// includes unchecked exceptions, e.g. ShutdownSignalException
throw new RMQJMSException("Cannot create browsing channel", e);
}
}
use of com.rabbitmq.client.ShutdownSignalException in project rabbitmq-jms-client by rabbitmq.
the class MessageListenerConsumer method stop.
@Override
public void stop() {
String cT = this.getConsTag();
logger.trace("consumerTag='{}'", cT);
TimeTracker tt = new TimeTracker(this.terminationTimeout, TimeUnit.NANOSECONDS);
try {
if (!this.completion.isComplete()) {
logger.debug("consumerTag='{}' basicCancel:", cT);
this.channel.basicCancel(cT);
this.completion.waitUntilComplete(tt);
this.clearConsTag();
}
} catch (TimeoutException te) {
Thread.currentThread().interrupt();
} catch (ShutdownSignalException sse) {
// TODO check if basicCancel really necessary in this case.
if (!sse.isInitiatedByApplication()) {
logger.error("basicCancel (consumerTag='{}') threw exception", cT, sse);
throw sse;
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (IOException e) {
if (!e.getMessage().equals("Unknown consumerTag")) {
logger.error("basicCancel (consumerTag='{}') threw unexpected exception", cT, e);
}
}
}
use of com.rabbitmq.client.ShutdownSignalException in project microservices by pwillhan.
the class FailoverReceiver method receive.
public void receive() {
Connection connection = null;
Channel channel = null;
try {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
connection = factory.newConnection();
channel = connection.createChannel();
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(REQUEST_QUEUE, false, consumer);
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
LOGGER.info("Request received: " + message);
channel.txSelect();
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
channel.txCommit();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
if (channel != null) {
try {
channel.txRollback();
} catch (IOException re) {
LOGGER.error("Rollback failed: " + re.getMessage(), re);
}
}
} catch (ShutdownSignalException e) {
LOGGER.error(e.getMessage(), e);
} catch (ConsumerCancelledException e) {
LOGGER.error(e.getMessage(), e);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (IOException e) {
LOGGER.warn("Failed to close connection: " + e.getMessage(), e);
}
}
}
}
use of com.rabbitmq.client.ShutdownSignalException in project microservices by pwillhan.
the class WSO2Sender 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;
}
Aggregations