Search in sources :

Example 61 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueManyMessagesAndInterrupt.

@Test
public void testSimpleMessageReceivedOnQueueManyMessagesAndInterrupt() throws Exception {
    final int SIZE = 14;
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(SIZE);
    CountDownLatch latchDone = new CountDownLatch(SIZE);
    MultipleEndpoints endpoint = new MultipleEndpoints(latch, latchDone, true);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    for (int i = 0; i < SIZE; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("teststring" + i);
        clientProducer.send(message);
    }
    session.close();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    latchDone.await(5, TimeUnit.SECONDS);
    assertEquals(SIZE, endpoint.messages.intValue());
    assertEquals(0, endpoint.interrupted.intValue());
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 62 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSimpleTopic.

@Test
public void testSimpleTopic() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("mdbTopic");
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("test");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "test");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 63 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSharedSubscription.

@Test
public void testSharedSubscription() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);
    ActiveMQActivationSpec spec2 = new ActiveMQActivationSpec();
    spec2.setResourceAdapter(qResourceAdapter);
    spec2.setUseJNDI(false);
    spec2.setDestinationType("javax.jms.Topic");
    spec2.setDestination("mdbTopic");
    spec2.setSubscriptionDurability("Durable");
    spec2.setSubscriptionName("durable-mdb");
    spec2.setClientID("id-1");
    spec2.setSetupAttempts(1);
    spec2.setShareSubscriptions(true);
    spec2.setMaxSession(1);
    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    CountDownLatch latch2 = new CountDownLatch(5);
    DummyMessageEndpoint endpoint2 = new DummyMessageEndpoint(latch2);
    DummyMessageEndpointFactory endpointFactory2 = new DummyMessageEndpointFactory(endpoint2, false);
    qResourceAdapter.endpointActivation(endpointFactory2, spec2);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("mdbTopic");
    for (int i = 0; i < 10; i++) {
        ClientMessage message = session.createMessage(true);
        message.getBodyBuffer().writeString("" + i);
        clientProducer.send(message);
    }
    session.commit();
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertTrue(latch2.await(5, TimeUnit.SECONDS));
    assertNotNull(endpoint.lastMessage);
    assertNotNull(endpoint2.lastMessage);
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.endpointDeactivation(endpointFactory2, spec2);
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 64 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testDeserialization.

private void testDeserialization(String blackList, String whiteList, boolean shouldSucceed) throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setDeserializationBlackList(blackList);
    qResourceAdapter.setDeserializationWhiteList(whiteList);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    // send using jms
    ActiveMQConnectionFactory jmsFactory = new ActiveMQConnectionFactory("vm://0");
    Connection connection = jmsFactory.createConnection();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue jmsQueue = session.createQueue(MDBQUEUE);
        ObjectMessage objMsg = session.createObjectMessage();
        objMsg.setObject(new DummySerializable());
        MessageProducer producer = session.createProducer(jmsQueue);
        producer.send(objMsg);
    } finally {
        connection.close();
    }
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    ObjectMessage objMsg = (ObjectMessage) endpoint.lastMessage;
    try {
        Object obj = objMsg.getObject();
        assertTrue("deserialization should fail but got: " + obj, shouldSucceed);
        assertTrue(obj instanceof DummySerializable);
    } catch (JMSException e) {
        assertFalse("got unexpected exception: " + e, shouldSucceed);
    }
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ObjectMessage(javax.jms.ObjectMessage) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) MessageProducer(javax.jms.MessageProducer) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) Queue(javax.jms.Queue) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession)

Example 65 with ActiveMQResourceAdapter

use of org.apache.activemq.artemis.ra.ActiveMQResourceAdapter in project activemq-artemis by apache.

the class ActiveMQMessageHandlerTest method testSimpleMessageReceivedOnQueueWithSelector.

@Test
public void testSimpleMessageReceivedOnQueueWithSelector() throws Exception {
    ActiveMQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    spec.setMessageSelector("color='red'");
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("blue");
    message.putStringProperty("color", "blue");
    clientProducer.send(message);
    message = session.createMessage(true);
    message.getBodyBuffer().writeString("red");
    message.putStringProperty("color", "red");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "red");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) CountDownLatch(java.util.concurrent.CountDownLatch) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)81 Test (org.junit.Test)72 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)54 CountDownLatch (java.util.concurrent.CountDownLatch)39 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)28 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)24 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)24 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)24 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)14 ConnectionFactoryProperties (org.apache.activemq.artemis.ra.ConnectionFactoryProperties)10 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)9 ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)8 Binding (org.apache.activemq.artemis.core.postoffice.Binding)7 HashSet (java.util.HashSet)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Role (org.apache.activemq.artemis.core.security.Role)5 ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 Session (javax.jms.Session)4