[ 
https://issues.apache.org/jira/browse/CAMEL-7024?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13835047#comment-13835047
 ] 

Joe Luo commented on CAMEL-7024:
--------------------------------

Simply using following code snippet to reproduce it:
{code}
public static void main(String args[]) throws Exception {
        CamelContext context = new DefaultCamelContext();
        ConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory("tcp://localhost:61616");
        context.addComponent("jms-test", 
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("direct:in").log(LoggingLevel.INFO, "endpointUri header: 
${header.endpointUri}").recipientList(header("endpointUri"));
            }
        });
        ProducerTemplate template = context.createProducerTemplate();
        context.start();

        String endpointUri = 
"jms-test:queue:test.request?replyTo=test.response&replyToType=Exclusive&concurrentConsumers=1&requestTimeout=2000";
        for (int i = 0; i < 10; i++) {
            Object ret = template.requestBodyAndHeader("direct:in", "Test 
Message: " + i, "endpointUri", endpointUri + i);
            System.out.println("returning: " + ret.toString());
            Thread.sleep(1000);
            System.out.println("removing endpoint");
            context.removeEndpoints("jms-test*");
        }
       
        // wait a bit and then stop
        Thread.sleep(10000);
        context.stop();
    }
{code}

You also need a server to consume message from the test.request queue and send 
a reply to test.response queue.

> Invoking removeEndpoints() api against a JmsEndpoint does not remove 
> associated Jms listener
> --------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-7024
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7024
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-jms
>    Affects Versions: 2.10.3
>            Reporter: Joe Luo
>
> I have a camel route that receives Camel Exchanges through JMS and based on 
> its content it builds on the fly the endpoint URI as a string. The URI 
> comprises a request queue and a response queue, and looks something similar 
> to:
> {code}
> jms-test:queue:test.request?replyTo=test.response&replyToType=Exclusive&requestTimeout=20000&concurrentConsumers=1
> {code}
> This URI is then used on a *ReceipientList* which sends the JMS message.
> Camel caches the above URI as one of its available endpoints, and registers a 
> listener (a DefaultMessageListenerContainer) against the response queue.
> Client determines some of the parameters, for instance the timeout to be 
> used. If a new exchange for instance uses a different timeout, Camel would 
> cache a second endpoint with similar URI except for the timeout, and would 
> create a second JMS listener (DMLC) on the same response queue.
> The above would create a conflict between the first listener and the second 
> as they would both compete for JMS response messages. For this reason I need 
> to remove the first endpoint using following Camel API:
> {code}
> Collection<Endpoint> removeEndpoints(String pattern) throws Exception;
> {code}
> For instance:
> {code}
> camelContext.removeEndpoints("jms-test*");
> {code}
> which successfully deletes it, but does not unsubscribe the JMS listener.
> The reason is that when Camel removes the endpoint, it does not invoke stop() 
> on associated JmsProducer object which in turn calls unInitReplyManager() to 
> stop and destroy the DMLC that is created by ReplyManager for the response 
> queue.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to