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");
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.QueueConnection in project spring-framework by spring-projects.
the class SingleConnectionFactory method createQueueConnection.
@Override
public QueueConnection createQueueConnection() throws JMSException {
Connection con;
synchronized (this.connectionMonitor) {
this.pubSubMode = Boolean.FALSE;
con = createConnection();
}
if (!(con instanceof QueueConnection)) {
throw new javax.jms.IllegalStateException("This SingleConnectionFactory does not hold a QueueConnection but rather: " + con);
}
return ((QueueConnection) con);
}
use of javax.jms.QueueConnection in project spring-framework by spring-projects.
the class TransactionAwareConnectionFactoryProxy method createQueueConnection.
@Override
public QueueConnection createQueueConnection() throws JMSException {
ConnectionFactory target = obtainTargetConnectionFactory();
if (!(target instanceof QueueConnectionFactory)) {
throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
}
QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection();
return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
use of javax.jms.QueueConnection in project opennms by OpenNMS.
the class DaemonContextIT method canUseEmbeddedActiveMQBroker.
/**
* Verifies that the embedded ActiveMQ broker bootstraps successfully
* and is accessible using the provided connection factory.
*/
@Test
public void canUseEmbeddedActiveMQBroker() throws Throwable {
QueueConnection connection = activeMQConnectionFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage();
message.setText("ping");
QueueSender sender = session.createSender(session.createQueue("pong"));
sender.send(message);
}
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