gpt4 book ai didi

java - 如何在 Java、Spring 和 Apache Camel 中定义 url

转载 作者:行者123 更新时间:2023-12-02 12:06:21 25 4
gpt4 key购买 nike

在 Apache Camel 中,我想将 XML 文件内容发送到 jms 队列。我的 Camel 代码中有:

 .to("jms:accounting");

所以我需要在我的camel-context.xml中定义jms。

我有

 xmlns:broker="http://activemq.apache.org/schema/core"

然后

<!-- ActiveMQ Broker -->
<broker:broker useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector name="tcp" uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>

<!-- JMS que -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</property>
</bean>

当我运行该项目时,我收到此错误:

[ERROR] Failed to execute goal org.apache.camel:camel-maven-plugin:2.20.0:run (default-cli) on project 08-xml-to-jms: null: MojoExecutionException: InvocationTargetException: Line 22 in XML document from file [/IdeaProjects/training/target/classes/META-INF/spring/camel-contxt.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 77; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'broker:broker'. -> [Help 1]

完整的POM文件:

<?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>com.domain.subdomain</groupId>
<artifactId>08-xml-to-jms</artifactId>
<version>1.0-SNAPSHOT</version>



<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.20.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-spring -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.20.0</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>spi-annotations</artifactId>
<version>2.20.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-jms -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.20.0</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http4</artifactId>
<version>2.20.0</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
<version>2.20.0</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-all -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.15.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.xbean/xbean-spring -->
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>4.5</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>


</dependencies>


<build>
<plugins>
<!-- Allows the routes to be run via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.20.0</version>
</plugin>
</plugins>
</build>

</project>

完整的camel-context.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:broker="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

<!-- Currency Route -->
<bean id="CurrencyRoute" class="com.domain.subdomain.route.CurrencyRoute">
<property name="currencyWsURL" value="www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml" />
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="CurrencyRoute"/>
</camelContext>


<!-- ActiveMQ Broker -->
<broker:broker useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector name="tcp" uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>

<!-- JMS que -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</property>
</bean>

</beans>

完整的Java代码:

package com.domain.subdomain.route;

import org.apache.camel.builder.RouteBuilder;

public class CurrencyRoute extends RouteBuilder {


private String currencyWsURL;



@Override
public void configure() {
from("quartz://myTimer?trigger.repeatCount=0")
.log("### Quartz trigger ###")
.to("direct:readFile");

from("direct:readFile")
.log("### Read file ###")
.to("https4://" + currencyWsURL)
.to("jms:accounting");
// .to("file:src/main/resources/data/work_in_progress?fileName=kursliste_ws-$simple{date:now:yyyyMMdd}.xml");
}

public void setCurrencyWsURL(String currencyWsURL) {
this.currencyWsURL = currencyWsURL;
}
}

最佳答案

更改部分

  <broker:broker useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector name="tcp" uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>

 <broker xmlns="http://activemq.apache.org/schema/core" useJmx="false" persistent="false" brokerName="localhost>
<transportConnectors>
<transportConnector name="tcp" uri="tcp://localhost:61616"/>
</transportConnectors>
</broker>

关于java - 如何在 Java、Spring 和 Apache Camel 中定义 <beans> url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46885975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com