use of javax.jms.QueueConnection 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");
final Callable<Void> callable = () -> {
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();
}
}
return null;
};
Util.switchIdentitySCF("user1", "password1", callable);
}
use of javax.jms.QueueConnection in project wildfly by wildfly.
the class HelloMDB method sendReply.
private void sendReply(String msg, Queue destination, String messageID) throws JMSException {
QueueConnection conn = qFactory.createQueueConnection("guest", "guest");
try {
QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
QueueSender sender = session.createSender(destination);
TextMessage message = session.createTextMessage(msg);
message.setJMSCorrelationID(messageID);
sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
} finally {
conn.close();
}
}
use of javax.jms.QueueConnection in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method sendMessage.
static Queue sendMessage(String text, String queueJndi, InitialContext initCtx) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
Queue replyDestination = null;
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage(text);
replyDestination = (Queue) initCtx.lookup(TransactionTimeoutQueueSetupTask.REPLY_QUEUE_JNDI_NAME);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) initCtx.lookup(queueJndi);
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
return replyDestination;
}
use of javax.jms.QueueConnection in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method receiveMessage.
static String receiveMessage(Queue replyQueue, InitialContext initCtx, boolean isCommitExpected) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final QueueReceiver receiver = session.createReceiver(replyQueue);
// when expecting commit (message should be in queue): wait a bit longer before failing
// when expecting rollback (message should not be in queue): fail faster only till timeout elapses
final Message reply = receiver.receive(TimeoutUtil.adjust(isCommitExpected ? 5000 : TxTestUtil.timeoutWaitTime_ms));
// waiting for synchro could be finished before checking
Thread.sleep(TimeoutUtil.adjust(500));
if (reply == null)
return null;
return ((TextMessage) reply).getText();
} finally {
connection.close();
}
}
use of javax.jms.QueueConnection in project Payara by payara.
the class MessageBean method onMessage.
public void onMessage(Message message) {
System.out.println("Got message!!!");
QueueConnection connection = null;
try {
System.out.println("Calling hello1 stateless bean");
hello1.hello("local ejb3.0 stateless");
System.out.println("Calling hello2 stateful bean");
hello2.hello("local ejb3.0 stateful");
hello2.removeMethod();
try {
hello2.hello("this call should not go through");
throw new Exception("bean should have been removed " + "after removeMethod()");
} catch (NoSuchEJBException e) {
System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
}
connection = qcFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(clientQueue);
TextMessage tmessage = session.createTextMessage();
tmessage.setText("mdb() invoked");
System.out.println("Sending message");
sender.send(tmessage);
System.out.println("message sent");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations