Search in sources :

Example 41 with QueueConnection

use of javax.jms.QueueConnection in project qpid-broker-j by apache.

the class QueueSessionTest method testQueueSessionCannotUnsubscribe.

@Test
public void testQueueSessionCannotUnsubscribe() throws Exception {
    QueueConnection queueConnection = getQueueConnection();
    try {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            queueSession.unsubscribe("abc");
            fail("expected exception did not occur");
        } catch (javax.jms.IllegalStateException s) {
        // PASS
        }
    } finally {
        queueConnection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 42 with QueueConnection

use of javax.jms.QueueConnection in project wildfly by wildfly.

the class MessageDrivenTimeoutTestCase method receiveMessage.

static String receiveMessage(Queue replyQueue, InitialContext initCtx) throws Exception {
    QueueConnection connection = getConnection(initCtx);
    connection.start();
    try {
        final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        final QueueReceiver receiver = session.createReceiver(replyQueue);
        final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
        // 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();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueReceiver(javax.jms.QueueReceiver) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Example 43 with QueueConnection

use of javax.jms.QueueConnection in project activemq-artemis by apache.

the class QueueReceiverTest method testCreateReceiverWithMessageSelector.

/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
    QueueConnection qc = null;
    try {
        qc = createQueueConnection();
        QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
        qc.start();
        TextMessage m = qs.createTextMessage();
        m.setText("one");
        m.setBooleanProperty("targetMessage", false);
        QueueSender qsender = qs.createSender(queue1);
        qsender.send(m);
        m.setText("two");
        m.setBooleanProperty("targetMessage", true);
        qsender.send(m);
        TextMessage rm = (TextMessage) qreceiver.receive(1000);
        ProxyAssertSupport.assertEquals("two", rm.getText());
    } finally {
        if (qc != null) {
            qc.close();
        }
        Thread.sleep(2000);
        removeAllMessages(queue1.getQueueName(), true);
        checkEmpty(queue1);
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueReceiver(javax.jms.QueueReceiver) QueueSender(javax.jms.QueueSender) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 44 with QueueConnection

use of javax.jms.QueueConnection in project activemq-artemis by apache.

the class SessionTest method testCreateTopicOnAQueueSession.

@Test
public void testCreateTopicOnAQueueSession() throws Exception {
    QueueConnection c = (QueueConnection) getConnectionFactory().createConnection();
    QueueSession s = c.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        s.createTopic("TestTopic");
        ProxyAssertSupport.fail("should throw IllegalStateException");
    } catch (javax.jms.IllegalStateException e) {
    // OK
    }
    c.close();
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 45 with QueueConnection

use of javax.jms.QueueConnection in project activemq-artemis by apache.

the class OutgoingConnectionTest method testSharedActiveMQConnectionFactoryWithClose.

@Test
public void testSharedActiveMQConnectionFactoryWithClose() throws Exception {
    Session s = null;
    Session s2 = null;
    ActiveMQRAManagedConnection mc = null;
    ActiveMQRAManagedConnection mc2 = null;
    try {
        server.getConfiguration().setSecurityEnabled(false);
        resourceAdapter = new ActiveMQResourceAdapter();
        resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
        MyBootstrapContext ctx = new MyBootstrapContext();
        resourceAdapter.start(ctx);
        ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
        ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
        mcf.setResourceAdapter(resourceAdapter);
        ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
        QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
        s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
        QueueConnection queueConnection2 = qraConnectionFactory.createQueueConnection();
        s2 = queueConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        mc2 = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s2).getManagedConnection();
        mc.destroy();
        MessageProducer producer = s2.createProducer(ActiveMQJMSClient.createQueue(MDBQUEUE));
        producer.send(s2.createTextMessage("x"));
    } finally {
        if (s != null) {
            s.close();
        }
        if (mc != null) {
            mc.destroy();
        }
        if (s2 != null) {
            s2.close();
        }
        if (mc2 != null) {
            mc2.destroy();
        }
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQRAConnectionManager(org.apache.activemq.artemis.ra.ActiveMQRAConnectionManager) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) XASession(javax.jms.XASession) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Aggregations

QueueConnection (javax.jms.QueueConnection)77 QueueSession (javax.jms.QueueSession)53 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)36 Queue (javax.jms.Queue)33 Message (javax.jms.Message)26 MessageProducer (javax.jms.MessageProducer)20 QueueConnectionFactory (javax.jms.QueueConnectionFactory)20 Session (javax.jms.Session)17 JMSException (javax.jms.JMSException)16 InitialContext (javax.naming.InitialContext)15 QueueSender (javax.jms.QueueSender)14 XAQueueConnection (javax.jms.XAQueueConnection)14 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)14 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)14 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)14 QueueReceiver (javax.jms.QueueReceiver)13 MessageConsumer (javax.jms.MessageConsumer)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)6