Search in sources :

Example 6 with ActiveMQActivation

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

the class ActiveMQMessageHandlerTest method testNonDurableSubscriptionDeleteAfterCrash.

// https://issues.jboss.org/browse/JBPAPP-8017
@Test
public void testNonDurableSubscriptionDeleteAfterCrash() 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("1");
    clientProducer.send(message);
    latch.await(5, TimeUnit.SECONDS);
    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "1");
    ActiveMQActivation activation = lookupActivation(qResourceAdapter);
    SimpleString tempQueueName = activation.getTopicTemporaryQueue();
    QueueQuery query = session.queueQuery(tempQueueName);
    assertTrue(query.isExists());
    // this should be enough to simulate the crash
    qResourceAdapter.getDefaultActiveMQConnectionFactory().close();
    qResourceAdapter.stop();
    query = session.queueQuery(tempQueueName);
    assertFalse(query.isExists());
}
Also used : ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery) Test(org.junit.Test)

Example 7 with ActiveMQActivation

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

the class ActiveMQResourceAdapter method endpointActivation.

/**
 * Endpoint activation
 *
 * @param endpointFactory The endpoint factory
 * @param spec            The activation spec
 * @throws ResourceException Thrown if an error occurs
 */
@Override
public void endpointActivation(final MessageEndpointFactory endpointFactory, final ActivationSpec spec) throws ResourceException {
    if (spec == null) {
        throw ActiveMQRABundle.BUNDLE.noActivationSpec();
    }
    if (!configured.getAndSet(true)) {
        try {
            setup();
        } catch (ActiveMQException e) {
            throw new ResourceException("Unable to create activation", e);
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("endpointActivation(" + endpointFactory + ", " + spec + ")");
    }
    ActiveMQActivation activation = new ActiveMQActivation(this, endpointFactory, (ActiveMQActivationSpec) spec);
    activations.put(spec, activation);
    activation.start();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) ResourceException(javax.resource.ResourceException)

Aggregations

ActiveMQActivation (org.apache.activemq.artemis.ra.inflow.ActiveMQActivation)7 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)6 ActiveMQActivationSpec (org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec)6 Test (org.junit.Test)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)3 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)3 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Connection (javax.jms.Connection)2 ResourceException (javax.resource.ResourceException)2 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)2 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1