use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class JMSClient method verifyOutputQueue.
private static void verifyOutputQueue(Session session) throws Exception {
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE_A));
int countA = 0;
while ((consumer.receive(30000)) != null) {
countA++;
}
consumer = session.createConsumer(session.createQueue(QUEUE_B));
int countB = 0;
while ((consumer.receive(1000)) != null) {
countB++;
}
consumer = session.createConsumer(session.createQueue(QUEUE_C));
int countC = 0;
while ((consumer.receive(1000)) != null) {
countC++;
}
System.out.println(QUEUE_A + "=" + countA + ", " + QUEUE_B + "=" + countB + ", " + QUEUE_C + "=" + countC);
}
use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class JmsBindingTest method testRollbackB.
@Test
public void testRollbackB() throws Exception {
String command = "rollback.B";
Connection conn = _connectionFactory.createConnection(HORNETQ_USER, HORNETQ_PASSWORD);
conn.start();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(_queueIn);
TextMessage message = session.createTextMessage();
message.setText(command);
producer.send(message);
session.close();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(_queueOutA);
TextMessage msg = TextMessage.class.cast(consumer.receive(1000));
Assert.assertEquals(command, msg.getText());
Assert.assertNull(consumer.receive(1000));
consumer.close();
consumer = session.createConsumer(_queueOutB);
msg = TextMessage.class.cast(consumer.receive(1000));
Assert.assertEquals(command, msg.getText());
Assert.assertNull(consumer.receive(1000));
consumer.close();
consumer = session.createConsumer(_queueOutC);
msg = TextMessage.class.cast(consumer.receive(1000));
Assert.assertEquals(command, msg.getText());
Assert.assertNull(consumer.receive(1000));
session.close();
} finally {
conn.close();
}
}
use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class JmsBindingTest method testNonTransacted.
@Test
public void testNonTransacted() throws Exception {
String command = "rollback.A";
Connection conn = _connectionFactory.createConnection(HORNETQ_USER, HORNETQ_PASSWORD);
conn.start();
try {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(_queueInNoTx);
TextMessage message = session.createTextMessage();
message.setText(command);
producer.send(message);
session.close();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(_queueOutA);
Assert.assertNull(consumer.receive(1000));
consumer = session.createConsumer(_queueOutB);
Assert.assertNull(consumer.receive(1000));
consumer = session.createConsumer(_queueOutC);
Assert.assertNull(consumer.receive(1000));
} finally {
conn.close();
}
}
use of javax.jms.MessageConsumer in project quickstarts by jboss-switchyard.
the class ActiveMQClient method main.
/**
* Only execution point for this application.
* @param ignored not used.
* @throws Exception if something goes wrong.
*/
public static void main(final String[] args) throws Exception {
String[] orders = { "BREAD", "PIZZA", "JAM", "POTATO", "MILK", "JAM" };
if (args.length != 0) {
orders = args;
}
ActiveMQMixIn mixIn = new ActiveMQMixIn();
try {
Session session = mixIn.getSession();
MessageProducer producer = session.createProducer(session.createQueue(ORDER_QUEUE));
for (String order : orders) {
final TextMessage message = session.createTextMessage();
message.setText(order);
producer.send(message);
}
session.close();
session = mixIn.getSession();
System.out.println("* * * SHIPPING ORDERS * * *");
MessageConsumer consumer = session.createConsumer(session.createQueue(SHIPPING_QUEUE));
Message msg = null;
while ((msg = consumer.receive(1000)) != null) {
if (msg instanceof TextMessage) {
System.out.println(" - " + ((TextMessage) msg).getText());
}
}
System.out.println();
System.out.println("* * * PENDING ORDERS (FILLING STOCK) * * *");
consumer = session.createConsumer(session.createQueue(FILLING_STOCK_QUEUE));
while ((msg = consumer.receive(1000)) != null) {
if (msg instanceof TextMessage) {
System.out.println(" - " + ((TextMessage) msg).getText());
}
}
session.close();
Thread.sleep(2000);
} finally {
mixIn.uninitialize();
}
}
use of javax.jms.MessageConsumer in project pinpoint by naver.
the class ActiveMQClientITBase method testQueuePush.
@Test
public void testQueuePush() throws Exception {
// Given
final String testQueueName = "TestPushQueue";
final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
final String testMessage = "Hello World for Queue!";
final CountDownLatch consumerLatch = new CountDownLatch(1);
final Collection<Throwable> consumerThrowables = new CopyOnWriteArrayList<Throwable>();
// create producer
ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
MessageProducer producer = producerSession.createProducer(testQueue);
final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
// create consumer
ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
MessageConsumer consumer = consumerSession.createConsumer(testQueue);
consumer.setMessageListener(new AssertTextMessageListener(consumerLatch, consumerThrowables, expectedTextMessage));
// When
producer.send(expectedTextMessage);
consumerLatch.await(1L, TimeUnit.SECONDS);
// Then
assertNoConsumerError(consumerThrowables);
// Wait till all traces are recorded (consumer traces are recorded from another thread)
awaitAndVerifyTraceCount(2, 5000L);
// trace count : 1
verifyProducerSendEvent(testQueue);
// trace count : 1
verifyConsumerPushEvent(testQueue);
}
Aggregations