Search in sources :

Example 46 with QueueConnection

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

the class OutgoingConnectionTest method testMultipleSessionsThrowsException.

@Test
public void testMultipleSessionsThrowsException() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        Session s2 = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        fail("should throw javax,jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
    } catch (JMSException e) {
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSException(javax.jms.JMSException) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) XASession(javax.jms.XASession) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) ActiveMQRASession(org.apache.activemq.artemis.ra.ActiveMQRASession) Test(org.junit.Test)

Example 47 with QueueConnection

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

the class OutgoingConnectionTest method testConnectionCredentialsFailRecovery.

@Test
public void testConnectionCredentialsFailRecovery() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    try {
        QueueConnection queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
        queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
        fail("should throw esxception");
    } catch (JMSException e) {
        // make sure the recovery is null
        assertNull(mcf.getResourceRecovery());
    }
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSException(javax.jms.JMSException) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 48 with QueueConnection

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

the class OutgoingConnectionJTATest method testQueuSessionAckMode.

public void testQueuSessionAckMode(boolean inTx) throws Exception {
    if (inTx) {
        setDummyTX();
    }
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    if (inTx) {
        assertEquals(Session.SESSION_TRANSACTED, s.getAcknowledgeMode());
    } else {
        assertEquals(Session.AUTO_ACKNOWLEDGE, s.getAcknowledgeMode());
    }
    s.close();
    s = queueConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    if (inTx) {
        assertEquals(Session.SESSION_TRANSACTED, s.getAcknowledgeMode());
    } else {
        assertEquals(Session.DUPS_OK_ACKNOWLEDGE, s.getAcknowledgeMode());
    }
    s.close();
    // CLIENT_ACKNOWLEDGE when in a JTA else ackmode should bee ignored
    try {
        s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
        if (inTx) {
            assertEquals(s.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
        } else {
            fail("didn't get expected exception creating session with SESSION_TRANSACTED mode ");
        }
        s.close();
    } catch (JMSException e) {
        if (inTx) {
            fail("shouldn't throw exception " + e);
        }
    }
    try {
        s = queueConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        if (inTx) {
            assertEquals(s.getAcknowledgeMode(), Session.SESSION_TRANSACTED);
        } else {
            fail("didn't get expected exception creating session with CLIENT_ACKNOWLEDGE mode");
        }
    } catch (JMSException e) {
        if (inTx) {
            fail("shouldn't throw exception " + e);
        }
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) JMSException(javax.jms.JMSException) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession)

Example 49 with QueueConnection

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

the class OutgoingConnectionNoJTATest method testSimpleMessageSendAndReceive.

@Test
public void testSimpleMessageSendAndReceive() throws Exception {
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
}
Also used : MessageConsumer(javax.jms.MessageConsumer) QueueConnection(javax.jms.QueueConnection) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 50 with QueueConnection

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

the class OutgoingConnectionNoJTATest method testSimpleMessageSendAndReceiveNotTransacted.

@Test
public void testSimpleMessageSendAndReceiveNotTransacted() throws Exception {
    setupDLQ(10);
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setAllowLocalTransactions(true);
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    s.commit();
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.rollback();
    textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.commit();
    textMessage = (TextMessage) consumer.receiveNoWait();
    assertNull(textMessage);
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) QueueConnection(javax.jms.QueueConnection) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) 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