Search in sources :

Example 1 with PasProducer

use of com.adaptris.core.jms.PasProducer in project interlok by adaptris.

the class DestinationCacheJndiPasProducerTest method testProduceAndConsumeWithCache.

@Test
public void testProduceAndConsumeWithCache() throws Exception {
    StandardJndiImplementation recvVendorImp = createVendorImplementation();
    StandardJndiImplementation sendVendorImp = createVendorImplementation();
    String queueName = testName.getMethodName() + "_queue";
    String topicName = testName.getMethodName() + "_topic";
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJndiPasConnection(recvVendorImp, false, queueName, topicName), new PasConsumer().withTopic(topicName));
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJndiPasConnection(sendVendorImp, false, queueName, topicName), new PasProducer().withTopic(topicName));
    try {
        start(standaloneConsumer);
        start(standaloneProducer);
        standaloneProducer.doService(createMessage(null));
        standaloneProducer.doService(createMessage(null));
        waitForMessages(jms, 2);
        assertMessages(jms, 2);
    } finally {
        stop(standaloneProducer);
        stop(standaloneConsumer);
    }
}
Also used : PasConsumer(com.adaptris.core.jms.PasConsumer) StandardJndiImplementation(com.adaptris.core.jms.jndi.StandardJndiImplementation) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 2 with PasProducer

use of com.adaptris.core.jms.PasProducer in project interlok by adaptris.

the class ActiveMqJmsTransactedWorkflowTest method testMessagesRolledBackUsingTopic.

@Test
public void testMessagesRolledBackUsingTopic() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesRolledBackUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        send(sender, msgCount);
        assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
// can't actually check the count of messsages on a topic, that's a trifle
// silly; you might check per-subscription...
// assertEquals(msgCount, activeMqBroker.messageCount(get(TOPIC)));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 3 with PasProducer

use of com.adaptris.core.jms.PasProducer in project interlok by adaptris.

the class ActiveMqPasPollingConsumerTest method testProduceConsume.

@Test
public void testProduceConsume() throws Exception {
    int msgCount = 5;
    final StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(testName.getMethodName()));
    final StandaloneConsumer receiver = createStandalone(activeMqBroker, "testProduceConsume", testName.getMethodName());
    try {
        MockMessageListener jms = new MockMessageListener();
        receiver.registerAdaptrisMessageListener(jms);
        startAndStop(receiver);
        start(receiver);
        start(sender);
        for (int i = 0; i < msgCount; i++) {
            sender.doService(createMessage());
        }
        waitForMessages(jms, msgCount);
        assertMessages(jms, msgCount);
    } finally {
        shutdownQuietly(sender, receiver);
    }
}
Also used : PasProducer(com.adaptris.core.jms.PasProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 4 with PasProducer

use of com.adaptris.core.jms.PasProducer in project interlok by adaptris.

the class BasicActiveMqConsumerTest method testTopicProduceAndConsumeWithExplicitFallbackMessageTranslation.

@Test
public void testTopicProduceAndConsumeWithExplicitFallbackMessageTranslation() throws Exception {
    PasConsumer consumer = new PasConsumer().withTopic(getName());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    consumer.setMessageTranslator(new AutoConvertMessageTranslator());
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl()), consumer);
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    DefinedJmsProducer producer = new PasProducer().withTopic(getName());
    producer.setMessageTranslator(new BytesMessageTranslator());
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), producer);
    execute(standaloneConsumer, standaloneProducer, createMessage(null), jms);
    assertMessages(jms, 1);
}
Also used : DefinedJmsProducer(com.adaptris.core.jms.DefinedJmsProducer) AutoConvertMessageTranslator(com.adaptris.core.jms.AutoConvertMessageTranslator) PasConsumer(com.adaptris.core.jms.PasConsumer) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) BytesMessageTranslator(com.adaptris.core.jms.BytesMessageTranslator) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 5 with PasProducer

use of com.adaptris.core.jms.PasProducer in project interlok by adaptris.

the class BasicActiveMqProducerTest method testTopicProduceAndConsume_DurableSubscriber_Legacy.

@Test
public void testTopicProduceAndConsume_DurableSubscriber_Legacy() throws Exception {
    String subscriptionId = GUID.safeUUID();
    String clientId = GUID.safeUUID();
    PasConsumer consumer = new PasConsumer().withTopic(getName());
    consumer.setSubscriptionId(subscriptionId);
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    JmsConnection conn = activeMqBroker.getJmsConnection(createVendorImpl(), true);
    conn.setClientId(clientId);
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(conn, consumer);
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    // Start it once to get some durable Action.
    start(standaloneConsumer);
    stop(standaloneConsumer);
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), new PasProducer().withTopic(getName()));
    int count = 10;
    for (int i = 0; i < count; i++) {
        ExampleServiceCase.execute(standaloneProducer, createMessage());
    }
    start(standaloneConsumer);
    waitForMessages(jms, count);
    assertMessages(jms, 10);
}
Also used : PasConsumer(com.adaptris.core.jms.PasConsumer) JmsConnection(com.adaptris.core.jms.JmsConnection) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

PasProducer (com.adaptris.core.jms.PasProducer)37 StandaloneProducer (com.adaptris.core.StandaloneProducer)34 Test (org.junit.Test)34 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)15 PasConsumer (com.adaptris.core.jms.PasConsumer)15 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)15 JmsConnection (com.adaptris.core.jms.JmsConnection)12 StandardJndiImplementation (com.adaptris.core.jms.jndi.StandardJndiImplementation)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)7 Channel (com.adaptris.core.Channel)5 MockChannel (com.adaptris.core.stubs.MockChannel)5 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 KeyValuePair (com.adaptris.util.KeyValuePair)5 BytesMessageTranslator (com.adaptris.core.jms.BytesMessageTranslator)4 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)4 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)3 RequiresCredentialsBroker (com.adaptris.core.jms.activemq.RequiresCredentialsBroker)3 DefinedJmsProducer (com.adaptris.core.jms.DefinedJmsProducer)2 TimeInterval (com.adaptris.util.TimeInterval)2 MimeEncoder (com.adaptris.core.MimeEncoder)1