use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class CcRoutes method expect.
private void expect(String[] expectedQueues, boolean usedCc) throws IOException {
GetResponse getResponse;
List<String> expectedList = Arrays.asList(expectedQueues);
for (String q : queues) {
getResponse = basicGet(q);
if (expectedList.contains(q)) {
assertNotNull(getResponse);
assertEquals(0, getResponse.getMessageCount());
Map<?, ?> headers = getResponse.getProps().getHeaders();
if (headers != null) {
assertEquals(usedCc, headers.containsKey("CC"));
assertFalse(headers.containsKey("BCC"));
}
} else {
assertNull(getResponse);
}
}
}
use of com.rabbitmq.client.GetResponse in project rabbitmq-java-client by rabbitmq.
the class AlternateExchange method checkGet.
/**
* Perform an auto-acking 'basic.get' on each of the queues named
* in {@link #resources} and check whether a message can be
* retrieved when expected.
*
* @param expected an array of booleans that is zipped with {@link
* #resources} and indicates whether a messages is expected
* to be retrievable from the respective queue
*/
protected void checkGet(boolean[] expected) throws IOException {
for (int i = 0; i < resources.length; i++) {
String q = resources[i];
GetResponse r = channel.basicGet(q, true);
assertEquals("check " + q, expected[i], r != null);
}
}
use of com.rabbitmq.client.GetResponse in project nifi by apache.
the class AMQPConsumerTest method validateSuccessfullConsumeWithEmptyQueueDefaultExchange.
@Test
public void validateSuccessfullConsumeWithEmptyQueueDefaultExchange() throws Exception {
Map<String, List<String>> routingMap = new HashMap<>();
routingMap.put("queue1", Arrays.asList("queue1"));
Map<String, String> exchangeToRoutingKeymap = new HashMap<>();
exchangeToRoutingKeymap.put("", "queue1");
Connection conn = new TestConnection(exchangeToRoutingKeymap, routingMap);
try (AMQPConsumer consumer = new AMQPConsumer(conn, "queue1")) {
GetResponse response = consumer.consume();
assertNull(response);
}
}
use of com.rabbitmq.client.GetResponse in project nifi by apache.
the class AMQPConsumerTest method validateSuccessfullConsumeWithEmptyQueue.
@Test
public void validateSuccessfullConsumeWithEmptyQueue() throws Exception {
Map<String, List<String>> routingMap = new HashMap<>();
routingMap.put("key1", Arrays.asList("queue1"));
Map<String, String> exchangeToRoutingKeymap = new HashMap<>();
exchangeToRoutingKeymap.put("myExchange", "key1");
Connection conn = new TestConnection(exchangeToRoutingKeymap, routingMap);
conn.createChannel().basicPublish("myExchange", "key1", null, "hello Joe".getBytes());
try (AMQPConsumer consumer = new AMQPConsumer(conn, "queue1")) {
GetResponse response = consumer.consume();
assertNotNull(response);
}
}
use of com.rabbitmq.client.GetResponse in project wso2-synapse by wso2.
the class RabbitMQConsumer method receive.
public MessageContext receive() {
if (!checkConnection()) {
if (!reconnect()) {
if (logger.isDebugEnabled()) {
logger.debug(getId() + " cannot receive message from store. Can not reconnect.");
}
return null;
} else {
logger.info(getId() + " reconnected to store.");
isReceiveError = false;
}
}
// setting channel
if (channel != null) {
if (!channel.isOpen()) {
if (!setChannel()) {
logger.info(getId() + " unable to create the channel.");
return null;
}
}
} else {
if (!setChannel()) {
logger.info(getId() + " unable to create the channel.");
return null;
}
}
// receive messages
try {
GetResponse delivery = null;
delivery = channel.basicGet(queueName, false);
if (delivery != null) {
// deserilizing message
StorableMessage storableMessage = null;
ByteArrayInputStream bis = new ByteArrayInputStream(delivery.getBody());
ObjectInput in = new ObjectInputStream(bis);
try {
storableMessage = (StorableMessage) in.readObject();
} catch (ClassNotFoundException e) {
logger.error(getId() + "unable to read the stored message" + e);
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
}
bis.close();
in.close();
org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc();
MessageContext synapseMc = store.newSynapseMc(axis2Mc);
synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc);
updateCache(delivery, synapseMc, null, false);
if (logger.isDebugEnabled()) {
logger.debug(getId() + " Received MessageId:" + delivery.getProps().getMessageId());
}
return synapseMc;
}
} catch (ShutdownSignalException sse) {
logger.error(getId() + " connection error when receiving messages" + sse);
} catch (IOException ioe) {
logger.error(getId() + " connection error when receiving messages" + ioe);
}
return null;
}
Aggregations