Apache Camel – DSL i OSGi

Apache Camel – DSL i OSGi

Apache Camel to lekka biblioteka która implementuje (EIP – wzorce integracji). Ten wpis ma na celu pokazanie w jaki sposób skonfigurować routing z użyciem Apache Camel i szyny Apache ServiceMix. Do dzieła, tworzymy nowy komponent OSGi! Projekt zaczynamy od utworzenia struktury projektu z użyciem Apache Maven bez zdefiniowanego archetypu – plik pom.xml:

<dependencies>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>2.16.5</version>
        <scope>provided</scope>
    </dependency>
 
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>2.16.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
 
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Plik ./resources/META-INF/beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring-2.10.3.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
    <package>pl.javaleader</package>
    <contextScan/>
</camelContext>
</beans>

Plik ./resources/META-INF/MANIFEST.MF

Manifest-Version: 1.0
Bundle-Name: camel-bundle-1
Bundle-SymbolicName: camel-bundle-1
Bundle-Version: 1.0.0
Bundle-Description: Camel Bundle 1
Bundle-Vendor: IT-eye
Bundle-Category: example
Import-Package: org.osgi.framework, org.apache.commons.logging, org.apache.camel.builder, org.apache.camel.model

w pakiecie pl.javaleader tworzymy klasę routingu z użyciem DSL (z ang. domain specific language).

public class FileRouteBuilder extends RouteBuilder {
    public void configure() {
        from("file:C:\\Users\\JL\\Downloads\\in?noop=true").to("file:C:\\Users\\JL\\Downloads\\out");
    }
}

testujemy dodając plik do katalogu in, moduł automatycznie powinien przekopiować plik do katalogu out.

Zobacz kod na GitHubie i zapisz się na bezpłatny newsletter!

.

Leave a comment

Your email address will not be published.


*