Here is the smallest problem that demonstrates the problem.

Java file

package test;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.*;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.bean.ProxyHelper;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.*;

public class ActiveMQTest {

    public static void main(String[] args) throws Exception {
        //log4j
        Logger.getRootLogger().addAppender(new ConsoleAppender(new 
PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN)));
        System.getProperties().put("org.apache.camel.jmx.disabled", "true");

        //needs at least 2 servers to see problem.
        simulatorServer("tcp://localhost:61616");
        simulatorServer("tcp://localhost:61617");
        simulatorServer("tcp://localhost:61618");

        //client
        CamelContext camelContext = new DefaultCamelContext();
        ActiveMQConfiguration configuration = new ActiveMQConfiguration();
        
configuration.setBrokerURL("failover://(tcp://localhost:61616,tcp://localhost:61617,tcp://localhost:61618)");
        camelContext.addComponent("jms", new ActiveMQComponent(configuration));
        camelContext.start();

        //invoke server. likely to fail when sleepTime is over 30 seconds
        Echo service = 
ProxyHelper.createProxy(camelContext.getEndpoint("jms:queue:echo"), Echo.class);
        int sleepTime = 31000;
        while (true) {
            System.out.println(service.echo("test"));
            Thread.sleep(sleepTime);
        }
    }

    private static void simulatorServer(final String url) throws Exception {
        //each server is listening on a dedicated broker
        BrokerService broker = new BrokerService();
        broker.setUseJmx(false);
        broker.setPersistent(false);
        broker.addConnector(url);
        broker.start();

        ActiveMQConfiguration configuration = new ActiveMQConfiguration();
        configuration.setBrokerURL(url);
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addComponent("jms", new ActiveMQComponent(configuration));

        camelContext.addRoutes(new RouteBuilder() {
            public void configure() {
                from("jms:queue:echo").bean(new Echo(){
                    public String echo(String text) {
                        return "Echo " + text + " from " + url;
                    }
                });
            }
        });
        camelContext.start();
    }

    //server interface
    public static interface Echo{
        String echo(String text);
    }
}


Pom file

<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>jmsproblem</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jmsproblem</name>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>5.3.0</version>
        </dependency>
    </dependencies>
</project>


On Nov 21, 2009, at 1:26 AM, Claus Ibsen wrote:

> On Sat, Nov 21, 2009 at 7:18 AM, Ming Fang <[email protected]> wrote:
>> Does anyone know of a fix for this?
>> This is a critical problem for us, and for many I would think since this is 
>> a very typical configuration.
>> 
> 
> Have you asked /searched at the AMQ forum also?
> 
> Try creating a small application that demonstrates your issue so its
> easier for others to try to reproduce the issue.
> And make that application as simple as possible so there are less
> moving parts to get confused by.
> 
> 
> 
>> On Nov 19, 2009, at 6:59 AM, Ming Fang wrote:
>> 
>>> Yes changing idelTimeOut in org.apache.activemq.pool.ConnectionPool to a 
>>> very large number would be a workaround.
>>> However I don't see anyway of doing that in 
>>> org.apache.activemq.camel.component.ActiveMQConfiguration.
>>> 
>>> But ultimately I think the way Camel uses JMS is just wrong;
>>> The use of a Requestor to listen for out messages will always be a problem 
>>> because it's not guarantee to be listening on the same broker as the 
>>> publisher.
>>> --ming
>>> 
>>> On Nov 19, 2009, at 4:42 AM, Willem Jiang wrote:
>>> 
>>>> Hi,
>>>> 
>>>> How about change the idle time of switching the broker ?
>>>> 
>>>> If the idle time is larger than your application response time, you will 
>>>> not get this kind trouble anymore.
>>>> 
>>>> Willem
>>>> 
>>>> Ming Fang wrote:
>>>>> Hi
>>>>> We're using Camel 2.0 with Activemq 5.3.
>>>>> Our app uses Camel jms remoting.
>>>>> It's connecting to two discrete ActiveMQ brokers using the failover 
>>>>> transport randomly. Everything works fine at first.
>>>>> The problem happens when the app is idle for more than 30 seconds. After 
>>>>> that any remote call will trigger Activemq client to reconnect and may 
>>>>> end up connecting to another broker. But the problem is the Requestor 
>>>>> does not reconnect and still connected to the original broker. The result 
>>>>> is calls are sent to one broker but the Requestor is listening to a 
>>>>> different broker for the response.
>>>>> Is there a way to force the Requestor to use the same connection as the 
>>>>> producers?
>>>>> --Ming
>>>> 
>>> 
>> 
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus

Reply via email to