Vitalii Tymchyshyn created CAMEL-7561:
-----------------------------------------

             Summary: ProducerCache used in DefaultProducerTemplate uses stale 
references after context restart
                 Key: CAMEL-7561
                 URL: https://issues.apache.org/jira/browse/CAMEL-7561
             Project: Camel
          Issue Type: Bug
    Affects Versions: 2.13.1
            Reporter: Vitalii Tymchyshyn


We've got ProducerTemplate injected into our beans that are used to call direct 
routes. Unfortunately after camel context restart we are starting to get 
DirectConsumerNotAvailableException. It looks like it's because of cache used. 
The workaround is to restart a template itself, but it's used in beans that 
don't know about context restarts.

Here is a test, only testTemplateRestart works now:
{noformat}
public class ContextRestartTest {

    CamelContext camelContext;
    ProducerTemplate template;

    @Before
    public void makeContext() throws Exception {
        camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new RouteBuilder(){

            @Override
            public void configure() throws Exception {
                from("direct:test").to("log:test");
            }
        });
        camelContext.start();
        template = camelContext.createProducerTemplate();
    }

    @After
    public void stopContext() throws Exception {
        template.stop();
        camelContext.stop();
    }

    @Test
    public void testDefaultURI() throws Exception {
        template.setDefaultEndpointUri("direct:test");
        template.sendBody("test");
        camelContext.stop();
        camelContext.start();
        template.sendBody("test");
    }

    @Test
    public void testGivenURI() throws Exception {
        template.sendBody("direct:test", "test");
        camelContext.stop();
        camelContext.start();
        template.sendBody("direct:test", "test");
    }

    @Test
    public void testTemplateRestart() throws Exception {
        template.sendBody("direct:test", "test");
        camelContext.stop();
        template.stop();
        template.start();
        camelContext.start();
        template.sendBody("direct:test", "test");
    }

}

{noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to