use of javax.jms.MessageConsumer in project wildfly by wildfly.
the class RunAsMDBUnitTestCase method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
Connection conn = connFactory.createConnection();
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
Queue queue = lookup("java:jboss/" + queueName, Queue.class);
MessageProducer producer = session.createProducer(queue);
producer.send(msg);
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
if (replyMsg instanceof ObjectMessage) {
Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
throw e;
}
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("SUCCESS", actual);
consumer.close();
producer.close();
session.close();
conn.close();
}
use of javax.jms.MessageConsumer in project wildfly by wildfly.
the class GetCallerPrincipalTestCase method testMDBLifecycle.
/**
* Run this one in the container so it can lookup the queue
* @throws Exception
*/
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
deployer.deploy("mdb");
SecurityClient client = this.login();
ITestResultsSingleton results = this.getResultsSingleton();
MessageProducer producer = null;
MessageConsumer consumer = null;
QueueConnection conn = null;
Session session = null;
try {
QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
conn = qcf.createQueueConnection("guest", "guest");
conn.start();
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
producer = session.createProducer(queue);
producer.send(msg);
consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Object obj = ((ObjectMessage) replyMsg).getObject();
log.trace("MDB message get: " + obj);
Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
deployer.undeploy("mdb");
Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
} finally {
if (consumer != null) {
consumer.close();
}
if (producer != null) {
producer.close();
}
if (session != null) {
session.close();
}
if (conn != null) {
conn.close();
}
client.logout();
}
}
use of javax.jms.MessageConsumer in project wildfly by wildfly.
the class JMSQueueManagementTestCase method removeJMSQueueRemovesAllMessages.
@Test
public void removeJMSQueueRemovesAllMessages() throws Exception {
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("A"));
MessageConsumer consumer = session.createConsumer(queue);
ModelNode result = execute(getQueueOperation("count-messages"), true);
Assert.assertTrue(result.isDefined());
Assert.assertEquals(1, result.asInt());
// remove the queue
adminSupport.removeJmsQueue(getQueueName());
// add the queue back
adminSupport.createJmsQueue(getQueueName(), EXPORTED_PREFIX + getQueueJndiName());
result = execute(getQueueOperation("count-messages"), true);
Assert.assertTrue(result.isDefined());
Assert.assertEquals(0, result.asInt());
}
use of javax.jms.MessageConsumer in project beam by apache.
the class JmsIOTest method testWriteMessage.
@Test
public void testWriteMessage() throws Exception {
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < 100; i++) {
data.add("Message " + i);
}
pipeline.apply(Create.of(data)).apply(JmsIO.write().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD));
pipeline.run();
Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
int count = 0;
while (consumer.receive(1000) != null) {
count++;
}
assertEquals(100, count);
}
use of javax.jms.MessageConsumer in project beam by apache.
the class JmsIOTest method testReadMessages.
@Test
public void testReadMessages() throws Exception {
// produce message
Connection connection = connectionFactory.createConnection(USERNAME, PASSWORD);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(session.createQueue(QUEUE));
TextMessage message = session.createTextMessage("This Is A Test");
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.send(message);
producer.close();
session.close();
connection.close();
// read from the queue
PCollection<JmsRecord> output = pipeline.apply(JmsIO.read().withConnectionFactory(connectionFactory).withQueue(QUEUE).withUsername(USERNAME).withPassword(PASSWORD).withMaxNumRecords(5));
PAssert.thatSingleton(output.apply("Count", Count.<JmsRecord>globally())).isEqualTo(new Long(5));
pipeline.run();
connection = connectionFactory.createConnection(USERNAME, PASSWORD);
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE));
Message msg = consumer.receiveNoWait();
assertNull(msg);
}
Aggregations