You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dragisa Krsmanovic <dk...@plos.org> on 2009/12/11 19:42:45 UTC
ActiveMQ 5.3.0 and PollingConsumer
This seems to be a problem between ActiveMQ and Camel (both 2.0.0 and
2.1.0)
Here is unit test:
==================================
@ContextConfiguration
public class PollingConsumerTest extends
AbstractTestNGSpringContextTests {
@EndpointInject(uri = "mock:end")
protected MockEndpoint endpoint;
@Produce(uri = "activemq:start")
protected ProducerTemplate start;
@Produce(uri = "activemq:inQueue")
protected ProducerTemplate inQueue;
@Test
@DirtiesContext
public void test() throws InterruptedException {
endpoint.setResultWaitTime(10000l);
endpoint.expectedMessageCount(1);
endpoint.message(0).body().isEqualTo("foo/bar/");
inQueue.sendBody("foo");
inQueue.sendBody("bar");
start.sendBody("start");
endpoint.assertIsSatisfied();
}
public static class Consumer {
private ConsumerTemplate consumerTemplate;
@EndpointInject(uri = "activemq:inQueue")
protected Endpoint endpoint;
@Required
public void setConsumerTemplate(ConsumerTemplate consumerTemplate) {
this.consumerTemplate = consumerTemplate;
}
@Handler
public String process() {
Exchange exchange;
StringBuilder result = new StringBuilder();
while ((exchange = consumerTemplate.receive(endpoint, 2000l)) !=
null) {
result.append(exchange.getIn().getBody(String.class)).append('/');
}
return result.toString();
}
}
public static class TestRoutes extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:start")
.to("bean:consumer")
.to("mock:end");
}
}
}
And corresponding context.xml:
==================================
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="transacted" value="true"/>
<property name="transactionManager" ref="jmsTransactionManager"/>
</bean>
<bean id="consumer" class="org.apache.camel.PollingConsumerTest
$Consumer">
<property name="consumerTemplate" ref="consumerTemplate"/>
</bean>
<bean id="routeBuilder" class="org.apache.camel.PollingConsumerTest
$TestRoutes"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<consumerTemplate id="consumerTemplate"/>
<routeBuilder ref="routeBuilder"/>
</camelContext>
</beans>
The test fails for activemq-camel 5.3.0 but succeeds for activemq-camel
5.2.0
Interesting thing is that test will succeed with activemq-camel 5.3.0 if
I take the transactional setup from context.xml (routes are not marked
as transacted). In other words, if I just have this for activemq in
context.xml:
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean>
This might be an ActiveMQ bug, but I better ask here first.
Thanks
--
Dragisa Krsmanovic
Java Developer
Public Library of Science
http://www.plos.org
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).
Re: ActiveMQ 5.3.0 and PollingConsumer
Posted by Dragisa Krsmanovic <dk...@plos.org>.
I created an issue for this problem
https://issues.apache.org/activemq/browse/CAMEL-2305
On Mon, 2009-12-14 at 10:28 -0800, Dragisa Krsmanovic wrote:
> Here is more details.
>
> On Fri, 2009-12-11 at 10:42 -0800, Dragisa Krsmanovic wrote:
> > @Test
> > @DirtiesContext
> > public void test() throws InterruptedException {
> > endpoint.setResultWaitTime(10000l);
> > endpoint.expectedMessageCount(1);
> > endpoint.message(0).body().isEqualTo("foo/bar/");
> > inQueue.sendBody("foo");
> > inQueue.sendBody("bar");
> > start.sendBody("start");
> > endpoint.assertIsSatisfied();
> > }
> >
> >
>
>
> It seems that scenario where a bean in one route consumes messages in
> another queue fails with Camel + ActiveMQ 5.3.0
>
> If I directly consume messages in my test method. The test will succeed.
>
> @Test
> @DirtiesContext
> public void test2() throws InterruptedException {
> inQueue.sendBody("foo");
> inQueue.sendBody("bar");
>
> Exchange exchange;
> int count = 0;
> while ((exchange = consumerTemplate.receive(inEndpoint, 2000l)) !=
> null) {
> count++;
> }
>
> assertEquals(count, 2);
>
> }
>
>
--
Dragisa Krsmanovic
Java Developer
Public Library of Science
http://www.plos.org
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).
Re: ActiveMQ 5.3.0 and PollingConsumer
Posted by Dragisa Krsmanovic <dk...@plos.org>.
Here is more details.
On Fri, 2009-12-11 at 10:42 -0800, Dragisa Krsmanovic wrote:
> @Test
> @DirtiesContext
> public void test() throws InterruptedException {
> endpoint.setResultWaitTime(10000l);
> endpoint.expectedMessageCount(1);
> endpoint.message(0).body().isEqualTo("foo/bar/");
> inQueue.sendBody("foo");
> inQueue.sendBody("bar");
> start.sendBody("start");
> endpoint.assertIsSatisfied();
> }
>
>
It seems that scenario where a bean in one route consumes messages in
another queue fails with Camel + ActiveMQ 5.3.0
If I directly consume messages in my test method. The test will succeed.
@Test
@DirtiesContext
public void test2() throws InterruptedException {
inQueue.sendBody("foo");
inQueue.sendBody("bar");
Exchange exchange;
int count = 0;
while ((exchange = consumerTemplate.receive(inEndpoint, 2000l)) !=
null) {
count++;
}
assertEquals(count, 2);
}
--
Dragisa Krsmanovic
Java Developer
Public Library of Science
http://www.plos.org
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).