You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Christian Müller <ch...@gmail.com> on 2012/12/18 22:24:04 UTC

Re: Camel ActiveMQ consumers do not consume after restart

Hello Marco!

Sorry for the late reply. Could you please have a look at the following
unit test, whether it fits your use case. It works with Camel 2.10.3 and
ActiveMQ 5.7.0:

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CamelActiveMqRestartTest {

    private BrokerService broker;
    private SimpleRegistry registry1, registry2;
    private CamelContext context1, context2;
    private ProducerTemplate template;

    @Before
    public void setUp() throws Exception {
        broker = new BrokerService();
        broker.setPersistent(true);
        broker.setUseJmx(false);
        broker.addConnector("tcp://localhost:61616");
        broker.start();

        registry1 = new SimpleRegistry();
        registry1.put("activemq",
ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));

        context1 = new DefaultCamelContext(registry1);
        context1.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:queue:q1")
                    .to("activemq:queue:q2");
            }
        });
        context1.start();

        template = context1.createProducerTemplate();
        template.start();

        registry2 = new SimpleRegistry();
        registry2.put("activemq",
ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));

        context2 = new DefaultCamelContext(registry2);
        context2.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:queue:q2")
                    .to("mock:end");
            }
        });
        context2.start();
    }

    @After
    public void tearDown() throws Exception {
        context2.stop();
        template.stop();
        context1.stop();

        broker.stop();
    }

    @Test
    public void test() throws Exception {
        context2.stop();
        MockEndpoint mock = (MockEndpoint) context2.getEndpoint("mock:end");
        mock.expectedMessageCount(5);

        for (int i = 0; i < 5; i++) {
            template.sendBody("activemq:queue:q1", "Camel");
        }

        mock.assertIsNotSatisfied();

        context2.start();

        mock.assertIsSatisfied();
    }
}

Best,
Christian

On Fri, Jul 20, 2012 at 4:25 PM, Marco Zapletal <ma...@gmail.com>wrote:

> C2 again




--