You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by camel_user <ma...@hotmail.com> on 2012/06/28 20:09:03 UTC
Question: Why are 2 connections created?
Hi,
I have a simple problem, but I can't figure out how to solve it.
I have the following piece of code (as an example) where I am using Qpid
AMQP broker and configuring 2 endpoints from 2 topics to route to the same
end point.
public class TestApp {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
new AMQAnyDestination("ADDR:queue_one; {create: always}");
new AMQAnyDestination("ADDR:queue_two; {create: always}");
final Component component =
AMQPComponent.amqpComponent("amqp://guest:guest@clientid/development?brokerlist='tcp://localhost:5672'");
context.addComponent("abc", component);
context.addRoutes(new RouteBuilder() {
public void configure() {
from("abc:topic:queue_one").to("direct:otherep");
from("abc:topic:queue_two").to("direct:otherep");
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
}
I expect that only one connection to the broker will be created and that all
messages that I receive on my 2 topics will route to the same
"direct:otherep" endpoint.
In practice however the behaviour is different. 2 connections are created to
the broker as seen from the following log extract:
2012-06-28 19:03:31,264 [INFO-main] qpid.client.AMQConnection -
Connection:amqp://guest:********@clientid/development?brokerlist='tcp://localhost:5672'
2012-06-28 19:03:32,168 [DEBUG-main] qpid.client.AMQConnection - Are we
connected:true
2012-06-28 19:03:32,174 [INFO-main] qpid.client.AMQConnection -
Connection:amqp://guest:********@clientid/development?brokerlist='tcp://localhost:5672'
2012-06-28 19:03:32,168 [DEBUG-main] qpid.client.AMQConnection - Are we
connected:true
Why is it that this creates 2 connections? I know it's something to do with
the way my routes are configured, but I can't figure out why.
Thanks!
--
View this message in context: http://camel.465427.n5.nabble.com/Question-Why-are-2-connections-created-tp5715235.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Question: Why are 2 connections created?
Posted by camel_user <ma...@hotmail.com>.
Thanks for your response Charles.
I am using connectionFactories in the actual code, this is just an example
to illustrate the problem.
But the point is if I have the same setup in spring XML I do not get this
problem. Only one connection is created.
What is so different between having a RouteBuilder and routes declared in
camel context in XML?
--
View this message in context: http://camel.465427.n5.nabble.com/Question-Why-are-2-connections-created-tp5715235p5715264.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Question: Why are 2 connections created?
Posted by Charles Moulliard <cm...@gmail.com>.
2 connections are created as there are 2 camel routes instancited and they
will use each one a AMQP client object to connect to your AMQP broker.
As AMQP component exends the Camel JMS component and uses Spring JMS
Template with DefaultMessageListenerContainer , I suggest that you setup a
connectionFactory for performance reasons and have a look to the following
documentation pages
JMS component : http://camel.apache.org/jms.html
http://camel.apache.org/jms.html
Spring DMLC :
http://bsnyderblog.blogspot.be/2010/02/using-spring-to-receive-jms-messages.html
Regards,
Charles
Apache Committer
--
View this message in context: http://camel.465427.n5.nabble.com/Question-Why-are-2-connections-created-tp5715235p5715250.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Question: Why are 2 connections created?
Posted by camel_user <ma...@hotmail.com>.
Any ideas anyone?
--
View this message in context: http://camel.465427.n5.nabble.com/Question-Why-are-2-connections-created-tp5715235p5715249.html
Sent from the Camel - Users mailing list archive at Nabble.com.