camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dragisa Krsmanovic <dkrsmano...@plos.org>
Subject ActiveMQ 5.3.0 and PollingConsumer
Date Fri, 11 Dec 2009 18:42:45 GMT
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&amp;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&amp;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).


Mime
View raw message