use of com.rabbitmq.client.Channel in project camel by apache.
the class RabbitMQProducer method execute.
/**
* Do something with a pooled channel (similar to Spring JDBC TransactionTemplate#execute)
*/
private <T> T execute(ChannelCallback<T> callback) throws Exception {
Channel channel;
try {
channel = channelPool.borrowObject();
} catch (IllegalStateException e) {
// Since this method is not synchronized its possible the
// channelPool has been cleared by another thread
checkConnectionAndChannelPool();
channel = channelPool.borrowObject();
}
if (!channel.isOpen()) {
log.warn("Got a closed channel from the pool");
// Reconnect if another thread hasn't yet
checkConnectionAndChannelPool();
channel = channelPool.borrowObject();
}
try {
return callback.doWithChannel(channel);
} finally {
channelPool.returnObject(channel);
}
}
use of com.rabbitmq.client.Channel in project camel by apache.
the class TemporaryQueueReplyManager method createListenerContainer.
@Override
protected Connection createListenerContainer() throws Exception {
log.debug("Creating connection");
Connection conn = endpoint.connect(executorService);
log.debug("Creating channel");
Channel channel = conn.createChannel();
// setup the basicQos
if (endpoint.isPrefetchEnabled()) {
channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(), endpoint.isPrefetchGlobal());
}
//Let the server pick a random name for us
DeclareOk result = channel.queueDeclare();
log.info("Using temporary queue name: {}", result.getQueue());
setReplyTo(result.getQueue());
//TODO check for the RabbitMQConstants.EXCHANGE_NAME header
channel.queueBind(getReplyTo(), endpoint.getExchangeName(), getReplyTo());
consumer = new RabbitConsumer(this, channel);
consumer.start();
return conn;
}
use of com.rabbitmq.client.Channel in project camel by apache.
the class RabbitMQConsumerIntTest method sentMessageWithTimestampIsReceived.
@Test
public void sentMessageWithTimestampIsReceived() throws InterruptedException, IOException, TimeoutException {
Date timestamp = currentTimestampWithoutMillis();
to.expectedMessageCount(1);
to.expectedHeaderReceived(RabbitMQConstants.TIMESTAMP, timestamp);
AMQP.BasicProperties.Builder properties = new AMQP.BasicProperties.Builder();
properties.timestamp(timestamp);
Channel channel = connection().createChannel();
channel.basicPublish(EXCHANGE, "", properties.build(), MSG.getBytes());
to.assertIsSatisfied();
}
use of com.rabbitmq.client.Channel in project camel by apache.
the class RabbitMQConsumerIntTest method sentMessageIsReceivedWithHeadersRoutingMultiValueMapBindings.
@Test
public void sentMessageIsReceivedWithHeadersRoutingMultiValueMapBindings() throws Exception {
to.expectedMessageCount(3);
Channel channel = connection().createChannel();
channel.basicPublish("ex7", "", propertiesWithHeader("fizz", "buzz"), MSG.getBytes());
channel.basicPublish("ex7", "", propertiesWithHeader("fizz", "buzz"), MSG.getBytes());
channel.basicPublish("ex7", "", propertiesWithHeader("fizz", "buzz"), MSG.getBytes());
channel.basicPublish("ex7", "", propertiesWithHeader("fizz", "nope"), MSG.getBytes());
to.assertIsSatisfied();
}
use of com.rabbitmq.client.Channel in project cloudstack by apache.
the class RabbitMQEventBus method stop.
@Override
public synchronized boolean stop() {
if (s_connection.isOpen()) {
for (String subscriberId : s_subscribers.keySet()) {
Ternary<String, Channel, EventSubscriber> subscriberDetails = s_subscribers.get(subscriberId);
Channel channel = subscriberDetails.second();
String queueName = subscriberId;
try {
channel.queueDelete(queueName);
channel.abort();
} catch (IOException ioe) {
s_logger.warn("Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage());
}
}
}
closeConnection();
return true;
}
Aggregations