Tag Archives: Apache Camel

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>
Advertisements

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

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:SampleQueue")...;
  }

}

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>

How to Send a Message to an Apache ActiveMQ Topic with Apache Camel

SampleActiveMQRouteBuilder.java

package br.eti.fernandoribeiro.sample.activemq;

import org.apache.camel.builder.RouteBuilder;

public final class SampleActiveMQRouteBuilder extends RouteBuilder {

  @Override
  public void configure() {
    ...setBody(constant("Simples Assim")).to("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>

How to Send a Message to an Apache ActiveMQ Queue with Apache Camel

SampleActiveMQRouteBuilder.java

package br.eti.fernandoribeiro.sample.activemq;

import org.apache.camel.builder.RouteBuilder;

public final class SampleActiveMQRouteBuilder extends RouteBuilder {

  @Override
  public void configure() {
    ...setBody(constant("Simples Assim")).to("activemq:SampleQueue");
  }

}

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>

How to Create an Apache CXF REST Web Service in Apache Camel

SampleResource.java

import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("sample")
public final class SampleResource {

  @Path("{param1}/{param2}")
  public Object sampleOperation(@PathParam("param1") final String param1, @PathParam("param2") final String param2) {
    return null;
  }

}

SampleRouteBuilder.java

import org.apache.camel.builder.RouteBuilder;

public final class SampleRouteBuilder extends RouteBuilder {

  @Override
  public void configure() {
    from("cxfrs:http://0.0.0.0:8080?resourceClasses=SampleResource")... // as per the doc, resourceClass should work
  }

}

How to Create an Apache CXF SOAP Proxy in Apache Camel with Apache Felix Maven Bundle Plugin

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>br.eti.fernandoribeiro.sample</groupId>
  <artifactId>cxfsample</artifactId>
  <packaging>bundle</packaging>
  <version>1.0</version>
  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.8.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-cxf</artifactId>
      <version>2.8.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.5</version>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <DynamicImport-Package>*</DynamicImport-Package> <!-- replacing several Apache CXF imports -->
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

SampleService.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.fernandoribeiro.eti.br/sample/cxf" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.fernandoribeiro.eti.br/sample/cxf" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:schema elementFormDefault="qualified" targetNamespace="http://www.fernandoribeiro.eti.br/sample/cxf">
      <xs:element name="Sample">
        <xs:complexType />
      </xs:element>
      <xs:element name="SampleResponse">
        <xs:complexType />
      </xs:element>
    </xs:schema>
  </wsdl:types>
  <wsdl:message name="Sample">
    <wsdl:part name="Sample" element="tns:Sample" />
  </wsdl:message>
  <wsdl:message name="SampleResponse">
    <wsdl:part name="SampleResponse" element="tns:SampleResponse" />
  </wsdl:message>
  <wsdl:portType name="SamplePortType">
    <wsdl:operation name="SampleOperation">
      <wsdl:input message="tns:Sample" />
      <wsdl:output message="tns:SampleResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="SampleSoapBinding" type="tns:SamplePortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="SampleOperation">
      <soap:operation soapAction="" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="SampleService">
    <wsdl:port name="SamplePort" binding="tns:SampleSoapBinding">
      <soap:address location="http://localhost/cxfsample/SampleService" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

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:cxf="http://camel.apache.org/schema/cxf" 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 http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
  <bean id="sampleRouteBuilder" class="br.eti.fernandoribeiro.sample.cxf.SampleRouteBuilder" />
  <camel:camelContext>
    <camel:routeBuilder ref="sampleRouteBuilder" />
  </camel:camelContext>
  <cxf:cxfEndpoint id="sampleCxfEndpoint" address="http://0.0.0.0:8080/cxfsample/SampleService" wsdlURL="wsdl/SampleService.wsdl" endpointName="sample:SamplePort" serviceName="sample:SampleService" xmlns:sample="http://www.fernandoribeiro.eti.br/sample/cxf" />
</beans>

How to Route by Apache CXF Operation in Apache Camel

import org.apache.camel.builder.RouteBuilder;

public final class SampleRouteBuilder extends RouteBuilder {

    public void configure() {
        from("cxf:bean:cxfEndpoint").choice().when(simple("${property.jaxwsContext[javax.xml.ws.wsdl.operation]} == '{http://www.fernandoribeiro.eti.br}FirstOperation'}")).when(simple("${property.jaxwsContext[javax.xml.ws.wsdl.operation]} == '{http://www.fernandoribeiro.eti.br}SecondOperation'}"));
    }

}