use of javax.jms.TemporaryQueue in project activemq-artemis by apache.
the class JMSReplyToHeaderTest method testJMSDestinationSimple.
// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testJMSDestinationSimple() throws Exception {
Message m = queueProducerSession.createMessage();
TemporaryQueue tempQ = queueProducerSession.createTemporaryQueue();
m.setJMSReplyTo(tempQ);
queueProducer.send(m);
queueConsumer.receive();
ProxyAssertSupport.assertEquals(tempQ, m.getJMSReplyTo());
}
use of javax.jms.TemporaryQueue in project wildfly by wildfly.
the class HelloBean method sendMessage.
/**
* Helper method to send message to {@link #QUEUE_NAME}.
*/
public static String sendMessage(ConnectionFactory cf) throws Exception {
Connection connection = null;
try {
Queue queue = cf.createContext("guest", "guest").createQueue(QUEUE_NAME);
connection = cf.createConnection("guest", "guest");
// we need to start connection for consumer
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TextMessage message = session.createTextMessage("hello goodbye");
TemporaryQueue replyQueue = session.createTemporaryQueue();
message.setJMSReplyTo(replyQueue);
sender.send(message);
log.tracef("Message '%s' sent", message);
// consume message processed by MDB
MessageConsumer consumer = session.createConsumer(replyQueue);
TextMessage replyMessage = (TextMessage) consumer.receive(TimeoutUtil.adjust(5000));
log.tracef("Message '%s' received", replyMessage);
if (replyMessage == null) {
return "ReplyMessage is 'null'. No response received from HelloMDB." + " Consult server log for details.";
}
return replyMessage.getText();
} finally {
try {
if (connection != null)
connection.close();
} catch (JMSException jmse) {
log.trace("connection close failed", jmse);
}
}
}
use of javax.jms.TemporaryQueue 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.TemporaryQueue 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.TemporaryQueue in project wildfly by wildfly.
the class ConnectionHoldingBean method createConnection.
@Override
public void createConnection() throws JMSException {
// create a consumer on a temp queue to ensure the Jakarta Messaging
// connection is actually created and started
context = factory.createContext("guest", "guest");
TemporaryQueue tempQueue = context.createTemporaryQueue();
context.createConsumer(tempQueue);
}
Aggregations