Search in sources :

Example 6 with QueueConnection

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();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 7 with QueueConnection

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);
}
Also used : QueueConnection(javax.jms.QueueConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection)

Example 8 with QueueConnection

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);
}
Also used : QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory)

Example 9 with QueueConnection

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);
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 10 with QueueConnection

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();
        }
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Aggregations

QueueConnection (javax.jms.QueueConnection)23 QueueSession (javax.jms.QueueSession)17 TextMessage (javax.jms.TextMessage)14 QueueConnectionFactory (javax.jms.QueueConnectionFactory)11 Test (org.junit.Test)10 Message (javax.jms.Message)8 MessageProducer (javax.jms.MessageProducer)7 Queue (javax.jms.Queue)7 QueueSender (javax.jms.QueueSender)7 Connection (javax.jms.Connection)5 Destination (javax.jms.Destination)5 QueueReceiver (javax.jms.QueueReceiver)5 TopicConnection (javax.jms.TopicConnection)5 InitialContext (javax.naming.InitialContext)5 ObjectMessage (javax.jms.ObjectMessage)3 ConnectionFactory (javax.jms.ConnectionFactory)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2 TopicConnectionFactory (javax.jms.TopicConnectionFactory)2 File (java.io.File)1