use of com.rabbitmq.client.Channel in project camel by apache.
the class RabbitMQConsumerIntTest method sentMessageIsReceived.
@Test
public void sentMessageIsReceived() throws InterruptedException, IOException, TimeoutException {
to.expectedMessageCount(1);
to.expectedHeaderReceived(RabbitMQConstants.REPLY_TO, "myReply");
AMQP.BasicProperties.Builder properties = new AMQP.BasicProperties.Builder();
properties.replyTo("myReply");
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 sentMessageIsReceivedWithHeadersRouting.
/**
* Tests the proper rabbit binding arguments are in place when the headersExchangeWithQueue is created.
* Should only receive messages with the header [foo=bar]
*/
@Test
public void sentMessageIsReceivedWithHeadersRouting() throws InterruptedException, IOException, TimeoutException {
//should only be one message that makes it through because only
//one has the correct header set
to.expectedMessageCount(1);
Channel channel = connection().createChannel();
channel.basicPublish(HEADERS_EXCHANGE, "", propertiesWithHeader("foo", "bar"), MSG.getBytes());
channel.basicPublish(HEADERS_EXCHANGE, "", null, MSG.getBytes());
channel.basicPublish(HEADERS_EXCHANGE, "", propertiesWithHeader("foo", "bra"), MSG.getBytes());
to.assertIsSatisfied();
}
use of com.rabbitmq.client.Channel in project camel by apache.
the class RabbitConsumer method openChannel.
/**
* Open channel
*/
private Channel openChannel(Connection conn) throws IOException {
log.trace("Creating channel...");
Channel channel = conn.createChannel();
log.debug("Created channel: {}", channel);
// setup the basicQos
if (consumer.getEndpoint().isPrefetchEnabled()) {
channel.basicQos(consumer.getEndpoint().getPrefetchSize(), consumer.getEndpoint().getPrefetchCount(), consumer.getEndpoint().isPrefetchGlobal());
}
// reconnections.
if (consumer.getEndpoint().isDeclare()) {
consumer.getEndpoint().declareExchangeAndQueue(channel);
}
return channel;
}
use of com.rabbitmq.client.Channel in project voltdb by VoltDB.
the class ExportRabbitMQVerifier method run.
public void run() throws IOException, InterruptedException {
final Connection connection = m_connFactory.newConnection();
final Channel channel = connection.createChannel();
try {
channel.exchangeDeclare(m_exchangeName, "topic", true);
String dataQueue = channel.queueDeclare().getQueue();
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE.#");
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE2.#");
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_REPLICATED_TABLE.#");
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE_FOO.#");
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_PARTITIONED_TABLE2_FOO.#");
channel.queueBind(dataQueue, m_exchangeName, "EXPORT_REPLICATED_TABLE_FOO.#");
String doneQueue = channel.queueDeclare().getQueue();
channel.queueBind(doneQueue, m_exchangeName, "EXPORT_DONE_TABLE.#");
channel.queueBind(doneQueue, m_exchangeName, "EXPORT_DONE_TABLE_FOO.#");
// Setup callback for data stream
channel.basicConsume(dataQueue, false, createConsumer(channel));
// Setup callback for the done message
QueueingConsumer doneConsumer = new QueueingConsumer(channel);
channel.basicConsume(doneQueue, true, doneConsumer);
// Wait until the done message arrives, then verify count
final QueueingConsumer.Delivery doneMsg = doneConsumer.nextDelivery();
final long expectedRows = Long.parseLong(ExportOnServerVerifier.RoughCSVTokenizer.tokenize(new String(doneMsg.getBody(), Charsets.UTF_8))[6]);
while (expectedRows > m_verifiedRows) {
Thread.sleep(1000);
System.err.println("Expected " + expectedRows + " " + m_verifiedRows);
}
} finally {
tearDown(channel);
channel.close();
connection.close();
}
}
use of com.rabbitmq.client.Channel in project cloudstack by apache.
the class RabbitMQEventBus method publish.
// publish event on to the exchange created on AMQP server
@Override
public void publish(Event event) throws EventBusException {
String routingKey = createRoutingKey(event);
String eventDescription = event.getDescription();
try {
Connection connection = getConnection();
Channel channel = createChannel(connection);
createExchange(channel, amqpExchangeName);
publishEventToExchange(channel, amqpExchangeName, routingKey, eventDescription);
channel.close();
} catch (AlreadyClosedException e) {
closeConnection();
throw new EventBusException("Failed to publish event to message broker as connection to AMQP broker in lost");
} catch (Exception e) {
throw new EventBusException("Failed to publish event to message broker due to " + e.getMessage());
}
}
Aggregations