[
https://issues.apache.org/jira/browse/CAMEL-7561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14051379#comment-14051379
]
Vitalii Tymchyshyn commented on CAMEL-7561:
-------------------------------------------
Yes, we've tried adding the template to context and indeed it was stopped and
never started again.
We are using @EndpointInject to get it into our beans.
As of usecase, it's HA solution and we've got LifecycleStrategy that stops the
context when node is out of quorum. We'll check if we can switch to
suspend/resume instead. Currently we are using suspend/resume for
single-node-only routes (we have route strategy for that), so we don't want to
have it mixed somehow in the wrong way.
As of fix, I though, Cache can check if passed and cached endpoint (or it's
component) is the same and invalidate cache entry if it's not.
Also, I'd document this limitation on
http://camel.apache.org/pojo-producing.html.
> 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
> Assignee: Claus Ibsen
>
> 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)