Browse Source

jms project building successfully level 2 complete

pranavE
pranavekapure 4 years ago
parent
commit
23c551670f
11 changed files with 577 additions and 0 deletions
  1. 17
      jms/.project
  2. 2
      jms/.settings/org.eclipse.core.resources.prefs
  3. 4
      jms/.settings/org.eclipse.m2e.core.prefs
  4. 18
      jms/README.md
  5. 378
      jms/pom.xml
  6. 2
      jms/src/data/message1.xml
  7. 47
      jms/src/main/java/camelinaction/OrderRouter.java
  8. 31
      jms/src/main/resources/META-INF/spring/camel-context.xml
  9. 15
      jms/src/main/resources/log4j.properties
  10. 46
      jms/src/test/java/camelinaction/RequestReplyJmsTest.java
  11. 17
      jms/src/test/java/camelinaction/ValidatorBean.java

17
jms/.project

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>chapter6-jms</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

2
jms/.settings/org.eclipse.core.resources.prefs

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

4
jms/.settings/org.eclipse.m2e.core.prefs

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

18
jms/README.md

@ -0,0 +1,18 @@
Chapter 6 - jms
----------------
This directory holds examples of the JMS component
### 6.3.1 - Sending and receiving JMS messages
To run this example, execute the following command:
mvn camel:run
This example will keep running until you press Ctrl-C.
### 6.3.2 - Request-reply messaging
To run this example, execute the following command:
mvn test -Dtest=RequestReplyJmsTest

378
jms/pom.xml

@ -0,0 +1,378 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.camelinaction</groupId>
<artifactId>chapter6-jms</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>
<name>Camel in Action 2</name>
<inceptionYear>2015</inceptionYear>
<properties>
<activemq-version>5.15.7</activemq-version>
<activemq-karaf-version>5.13.8</activemq-karaf-version>
<camel-version>2.25.0</camel-version>
<cxf-version>3.3.5</cxf-version>
<hawtio-version>1.4.68</hawtio-version>
<commons-dbcp2-version>2.5.0</commons-dbcp2-version>
<deltaspike-version>1.9.0</deltaspike-version>
<hystrix-version>1.5.18</hystrix-version>
<jackson-version>2.9.9</jackson-version>
<javax-mail-version>1.6.1</javax-mail-version>
<jolokia-version>1.6.0</jolokia-version>
<jetty-plugin-version>8.1.17.v20150415</jetty-plugin-version>
<jetty9-plugin-version>9.4.18.v20190429</jetty9-plugin-version>
<junit-version>4.12</junit-version>
<karaf-version>4.2.1</karaf-version>
<log4j-version>1.2.17</log4j-version>
<maven-bundle-plugin-version>3.3.0</maven-bundle-plugin-version>
<mock-javamail-version>1.9</mock-javamail-version>
<slf4j-version>1.7.25</slf4j-version>
<spring-version>5.1.6.RELEASE</spring-version>
<spring-boot-version>2.1.4.RELEASE</spring-boot-version>
<swagger-version>1.5.21</swagger-version>
<xbean-version>4.5</xbean-version>
<vertx-version>3.6.3</vertx-version>
<weld-version>2.4.7.Final</weld-version>
<wildfly-swarm-version>2017.11.0</wildfly-swarm-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-parent</artifactId>
<version>${camel-version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>spi-annotations</artifactId>
<version>${camel-version}</version>
</dependency>
<!-- ActiveMQ -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>${activemq-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>${activemq-version}</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>${xbean-version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j-version}</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
</dependency>
<!-- Jolokia -->
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
<version>${jolokia-version}</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring-version}</version>
</dependency>
<!-- Java FTP server -->
<dependency>
<groupId>org.apache.ftpserver</groupId>
<artifactId>ftpserver-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.ftpserver</groupId>
<artifactId>ftplet-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>${camel-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>${camel-version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq-version}</version>
</dependency>
<!-- xbean is needed for ActiveMQ broker XML configuration in Spring XML files -->
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>${xbean-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</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>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<maxmem>512M</maxmem>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>activemq-data</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel-version}</version>
</plugin>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-package-maven-plugin</artifactId>
<version>${camel-version}</version>
</plugin>
<plugin>
<groupId>io.hawt</groupId>
<artifactId>hawtio-maven-plugin</artifactId>
<version>${hawtio-version}</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-api-component-maven-plugin</artifactId>
<version>${camel-version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha11</version>
</plugin>
</plugins>
</build>
</project>

2
jms/src/data/message1.xml

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<order name="motor" amount="1" customer="honda"/>

47
jms/src/main/java/camelinaction/OrderRouter.java

@ -0,0 +1,47 @@
package camelinaction;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
/**
* A set of routes that watches a directory for new orders, reads them, converts the order
* file into a JMS Message and then sends it to the JMS incomingOrders queue hosted
* on an embedded ActiveMQ broker instance.
*
* From there a content-based router is used to send the order to either the
* xmlOrders or csvOrders queue.
*/
public class OrderRouter extends RouteBuilder {
@Override
public void configure() {
// load file orders from src/data into the JMS queue
from("file:src/data?noop=true").to("jms:incomingOrders");
// content-based router
from("jms:incomingOrders")
.choice()
.when(header("CamelFileName").endsWith(".xml"))
.to("jms:topic:xmlOrders")
.when(header("CamelFileName").endsWith(".csv"))
.to("jms:topic:csvOrders");
from("jms:topic:xmlOrders").to("jms:accounting");
from("jms:topic:xmlOrders").to("jms:production");
// test that our route is working
from("jms:accounting").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Accounting received order: "
+ exchange.getIn().getHeader("CamelFileName"));
}
});
from("jms:production").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Production received order: "
+ exchange.getIn().getHeader("CamelFileName"));
}
});
}
}

31
jms/src/main/resources/META-INF/spring/camel-context.xml

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<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.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">
<!-- set up ActiveMQ broker -->
<broker:broker useJmx="false" persistent="false" brokerName="localhost">
<broker:transportConnectors>
<broker:transportConnector name="tcp" uri="tcp://localhost:61616"/>
</broker:transportConnectors>
</broker:broker>
<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>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>camelinaction</package>
</camelContext>
</beans>

15
jms/src/main/resources/log4j.properties

@ -0,0 +1,15 @@
#
# The logging properties used for eclipse testing, We want to see INFO output on the console.
#
log4j.rootLogger=INFO, out
# uncomment the next line to debug Camel
#log4j.logger.org.apache.camel=DEBUG
# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer

46
jms/src/test/java/camelinaction/RequestReplyJmsTest.java

@ -0,0 +1,46 @@
package camelinaction;
import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class RequestReplyJmsTest extends CamelTestSupport {
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
camelContext.addComponent("jms", jmsComponentClientAcknowledge(connectionFactory));
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jms:incomingOrders").inOut("jms:validate");
from("jms:validate").bean(ValidatorBean.class);
}
};
}
@Test
public void testClientGetsReply() throws Exception {
Object requestBody = template.requestBody("jms:incomingOrders", "<order name=\"motor\" amount=\"1\" customer=\"honda\"/>");
assertEquals("Valid", requestBody);
}
@Test
public void testInvalidMessage() throws Exception {
Object requestBody = template.requestBody("jms:incomingOrders", "<order name=\"fork\" amount=\"1\" customer=\"honda\"/>");
assertEquals("Invalid", requestBody);
}
}

17
jms/src/test/java/camelinaction/ValidatorBean.java

@ -0,0 +1,17 @@
package camelinaction;
import org.apache.camel.Exchange;
import org.apache.camel.language.XPath;
public class ValidatorBean {
public void validate(@XPath("/order/@name") String partName, Exchange exchange) {
// only motors are valid parts in this simple test bean
if ("motor".equals(partName)) {
exchange.getOut().setBody("Valid");
} else {
exchange.getOut().setBody("Invalid");
}
}
}
Loading…
Cancel
Save