How to Receive a Message from an Apache ActiveMQ Topic with Apache Camel

W/o Durability

SampleActiveMQRouteBuilder.java

package br.eti.fernandoribeiro.sample.activemq;

import org.apache.camel.builder.RouteBuilder;

public final class SampleActiveMQRouteBuilder extends RouteBuilder {

  @Override
  public void configure() {
    from("activemq:topic:SampleTopic")...;
  }

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" 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.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
  <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61616" />
  </bean>
  <bean id="sampleActiveMQRouteBuilder" class="br.eti.fernandoribeiro.sample.activemq.SampleActiveMQRouteBuilder" />
  <camel:camelContext>
    <camel:routeBuilder ref="sampleActiveMQRouteBuilder" />
  </camel:camelContext>
</beans>

W/ Durability

SampleActiveMQRouteBuilder.java

package br.eti.fernandoribeiro.sample.activemq;

import org.apache.camel.builder.RouteBuilder;

public final class SampleActiveMQRouteBuilder extends RouteBuilder {

  @Override
  public void configure() {
    from("activemq:topic:SampleTopic?clientId=SampleClient&durableSubscriptionName=SampleSubscription")...;
  }

}

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" 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.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
  <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61616" />
  </bean>
  <bean id="sampleActiveMQRouteBuilder" class="br.eti.fernandoribeiro.sample.activemq.SampleActiveMQRouteBuilder" />
  <camel:camelContext>
    <camel:routeBuilder ref="sampleActiveMQRouteBuilder" />
  </camel:camelContext>
</beans>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s