MJar
MJar

Reputation: 784

Cannot set ActiveMQ destination option in Camel endpoint

I'm trying to set up prefetch policy on a Camel JMS (ActiveMQ) consumer. According to Camel documentation http://camel.apache.org/activemq.html#ActiveMQ-UsingActiveMQDestinationOptions I should be able to do this by adding ?destination.consumer.prefetchSize=1 to the endpoint URL.

Unfortunately when I do this I get following exception

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: activemq://queue:ToSynchronize?destination.consumer.prefetchSize=1 due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{destination.consumer.prefetchSize=1}]
    at org.apache.camel.impl.DefaultComponent.validateParameters(DefaultComponent.java:183)
    at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:128)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:558)
    ... 48 more

I have a simple route builder

@Component
public class IntegrationRout extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("activemq:queue:ToSynchronize?destination.consumer.prefetchSize=1")
            .unmarshal().jaxb("com.foo.jms.model")
            .beanRef("Service", "upload")
    }
}

And a Spring configuration in Java (taken from some tutorial on how to configure JMS transactional client)

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.foo"})
public class SynchronizationConfiguration extends CamelConfiguration {

    @Bean
    public ConnectionFactory jmsConnectionFactory() {
        return new ActiveMQConnectionFactory("tcp://localhost:61616");
    }

    @Bean
    @Autowired
    public PlatformTransactionManager jmsTransactionManager(final ConnectionFactory jmsConnectionFactory) {
        return new JmsTransactionManager(jmsConnectionFactory);
    }

    @Bean
    @Autowired
    public JmsComponent activemq(final ConnectionFactory jmsConnectionFactory, final PlatformTransactionManager jmsTransactionManager) {
        return JmsComponent.jmsComponentTransacted(jmsConnectionFactory, jmsTransactionManager);
    }
}

Upvotes: 2

Views: 1745

Answers (1)

MJar
MJar

Reputation: 784

In case of configuring ActiveMQ destination options like ?destination.consumer.prefetchSize=1 you have to explicitly use ActiveMQComponent class. Using the general JmsComponent won't work.

So you have to replace

    @Bean
    @Autowired
    public JmsComponent activemq(final ConnectionFactory jmsConnectionFactory, final PlatformTransactionManager jmsTransactionManager) {
        return JmsComponent.jmsComponentTransacted(jmsConnectionFactory, jmsTransactionManager);
    }

with something like

    @Bean
    @Autowired
    public JmsComponent activemq(final ConnectionFactory jmsConnectionFactory, final PlatformTransactionManager jmsTransactionManager) {
        final ActiveMQComponent activemq = new ActiveMQComponent();
        activemq.setConnectionFactory(jmsConnectionFactory);
        activemq.setTransactionManager(jmsTransactionManager);
        activemq.setTransacted(true);
        return activemq;
    }

Upvotes: 1

Related Questions