2

例を使用してSpring + Apache Camelいます。先ほどのこの例では、 を使用してcamel-core version 2.15.1いました。依存関係を更新し2.17.3たところ、依存関係を更新すると、以下のメソッドが非推奨になることがわかります。

CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);

そのための交換コードは何ですか?

以下の私のコードを参照してください: CamelTimerFeedingActiveMqExample

public class CamelTimerFeedingActiveMqExample {
    public static final void main(String[] args) throws Exception {
        ApplicationContext appContext = new ClassPathXmlApplicationContext("timerFeedActiveMqApplicationContext.xml");
        CamelContext camelContext = SpringCamelContext.springCamelContext(appContext, false);
        try {
            camelContext.start();
            Thread.sleep(5000);
        } finally {
            camelContext.stop();
        }
    }
}

applicationContext.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"
    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="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost?broker.persistent=false" />
    </bean>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="activemq:queue:numbers" />
            <to uri="log:com.javarticles?level=INFO&amp;groupInterval=10000" />
        </route>
    </camelContext> 
</beans>

timerFeedActiveMqApplicationContext.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"
    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="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost?broker.persistent=false" />
    </bean>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="connectionFactory" ref="connectionFactory" />
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route id="timerPingToInQueue">
            <from uri="timer:ping?period=1s" />
            <transform>
                <simple>Ping at ${date:now:yyyy-MM-dd HH:mm:ss}</simple>
            </transform>
            <to uri="activemq:queue:ping_queue" />
        </route>
        <route id="InQueueToConsole">
            <from uri="activemq:queue:ping_queue" />
            <to uri="stream:out" />
        </route>
    </camelContext>
</beans>

timerSelectQueryApplicationContext.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:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

    <context:property-placeholder location="classpath:database.properties"/>

    <bean id="orderProcessor" class="com.javarticles.camel.components.OrderProcessor"/>

    <jdbc:initialize-database data-source="dataSource" enabled="true">
        <jdbc:script location="classpath:db-schema.sql" />
        <jdbc:script location="classpath:db-test-data.sql" />
    </jdbc:initialize-database>


    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${mysql.driver.class.name}" />
        <property name="url" value="${mysql.url}" />
        <property name="username" value="${mysql.username}" />
        <property name="password" value="${mysql.username}" />
    </bean>

    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="timer://queryTimer?period=2s" />
            <setBody>
                <constant>
                    SELECT * FROM ORDERS WHERE STATUS='NEW' ORDER BY NAME
                </constant>
            </setBody>
            <to uri="jdbc:dataSource" />
            <split>
                <simple>${body}</simple>
                <to uri="bean:orderProcessor" />
            </split>
        </route>
    </camelContext>
</beans>

pom.xml

<properties>
        <!-- General Properties -->
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- Apache Camel -->
        <apache.camel.version>2.17.3</apache.camel.version>

        <!-- Spring Framework -->
        <spring.version>4.3.1.RELEASE</spring.version>

        <!-- MYSQL -->
        <mysql.version>5.1.39</mysql.version>

        <!-- Logging Framework -->
        <logback.version>1.1.7</logback.version>
        <jcl-over-slf4j.version>1.7.21</jcl-over-slf4j.version>

        <!-- Junit Framework -->
        <junit.version>4.12</junit.version>
    </properties>


    <dependencies>
        <!-- Spring Context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Spring JDBC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Camel core -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${apache.camel.version}</version>
        </dependency>

        <!-- camel stream -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-stream</artifactId>
            <version>${apache.camel.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>${apache.camel.version}</version>
        </dependency>

        <!-- camel spring -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>${apache.camel.version}</version>
        </dependency>

        <!-- camel JDBC -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jdbc</artifactId>
            <version>${apache.camel.version}</version>
        </dependency>

        <!-- MYSQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

画像: ここに画像の説明を入力

4

1 に答える 1

9

以下を使用するだけです。終わり !

public class CamelTimerSqlQueryExample {
    public static final void main(String[] args) throws Exception {
        ApplicationContext appContext = new ClassPathXmlApplicationContext("timerSelectQueryApplicationContext.xml");
        CamelContext camelContext = new SpringCamelContext(appContext) ;
        try {
            camelContext.start();
            Thread.sleep(5000);
        } finally {
            camelContext.stop();
        }
    }
}
于 2016-09-02T18:25:47.720 に答える