Reputation: 579
In Apache Camel I want to send a XML file contents to a jms queue. I have in my Camel code:
.to("jms:accounting");
So I need to define jms in my camel-context.xml.
I have
xmlns:broker="http://activemq.apache.org/schema/core"
Then
<!-- 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>
When I run the project i get this error:
[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]
Complete POM file:
<?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>
Complete 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>
Complete Java code:
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;
}
}
Upvotes: 0
Views: 609
Reputation: 579
I also found out that the broker schema has to defined in xsi:schemaLocation tag.
<?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://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
Upvotes: 0
Reputation: 3225
change the part from
<broker:broker useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector name="tcp" uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>
to
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="false" persistent="false" brokerName="localhost>
<transportConnectors>
<transportConnector name="tcp" uri="tcp://localhost:61616"/>
</transportConnectors>
</broker>
Upvotes: 1