3. Environment Setup
§ JDK 1.8+ Pre-Requisite ($JAVA_HOME in path)
§ Maven 3.3.3+ Pre-Requisite ($MAVEN_HOME in path)
§ Download and unzip ActiveMQ – Version 5.14.0+
§ Download hawtio – Version:1.4.56+
§ rename hawtio-app.jar
§ Download (Clone) Code From Github
§ https://github.com/jtdeane/magic-supplies
§ https://github.com/jtdeane/message-client
§ https://github.com/jtdeane/docker-message-client
§ https://github.com/jtdeane/camel-standalone-router
§ Windows Install ActiveMQ as Service:
./$ACTIVEMQ_HOME/win65/InstallService.bat
Docker Commands: ../docker-message-client/Enterprise Messaging Fundamentals Commands
Non-Docker Commands: ../message-client/Enterprise Messaging Fundamentals Commands
4. Docker – Portainer Setup
1. Create Volume
2. Start Portainer (no –v arg /var..sock for windows)
3. View Portainer (change admin password first time)
docker volume create portainer_data
docker run -d -p 9898:9000 -v /var/run/docker.sock:/var/run/docker.sock
-v portainer_data:/data portainer/portainer
http://localhost:9898/#/auth
5. Asynchronous Hello World!
1. Start ActiveMQ
2. Build Magic Supplies Project
3. Optional import into IDE
4. Execute Message Producer – Run as JUnit Test
5. View ActiveMQ Console
6. Execute Message Consumer – Run as JUnit Test
cd $ACTIVEMQ_HOME/bin
./activemq start OR ./activemq.bat
cd magic-supplies
mvn clean install
Open http://localhost:8161/admin/ {admin/admin}
Open http://localhost:8161/admin/queues.jsp
mvn test -Dtest=JMSProducerFunctionalTest
mvn test -Dtest=JMSConsumerFunctionalTest
6. ActiveMQ Web Console Alternative: hawtio
1. Start hawtio
2. Open in Web Browser
3. Select ConnectàLocal
4. Connect to ActiveMQ
5. Click new Agent URL to launch browsing
6. Select ActiveMQ
java -jar hawtio-app.jar --port 8090
http://localhost:8090/hawtio
8. Magic Supplies Web Services
1. Start ActiveMQ *
2. Start Web Application
3. Open Browser
4. View Health Check Response
* Web Application requires ActiveMQ started
cd $ACTIVEMQ_HOME/bin
./activemq start OR ./activemq.bat
mvn spring-boot:run -Drun.arguments="-Xmx256m,-Xms128m”
OR
cd magic-supplies/target
java -jar magic-supplies-1.0.0.jar
http://localhost:8080/info
{"build":{"description":"Magic Supplies Web Application","name":"Magic Supplies Web
Appication","version":"1.0.0","artifact":"magic-supplies"}}
9. Magic Supplies Web Services - Docker
1. Update Docker Compose
2. Build & Start Docker Compose
3. View Health Check Response
4. Displayed
Also starts ActiveMQ (http://localhost:8161/admin/) & Hawtio (http://localhost:8090/hawtio)
#replace magic supplies build
build: .
#with magic supplies image
image: jtdeane/magic-supplies:latest
docker-compose up
http://localhost:8080/info
{"build":{"description":"Magic Supplies Web Application","name":"Magic Supplies Web
Appication","version":"1.0.0","artifact":"magic-supplies"}}
10. Hawtio connect to ActiveMQ - Docker
1. Open in Browser
2. Connect Remote to ActiveMQ (admin/admin)
3. View Queues
http://localhost:8090/hawtio
33. ActiveMQ High Availability Demo
4. Update Slave ../conf/activemq.xml: Name, Management,
Persistence, Network, Transport Configurations
5. Update Slave ../conf/jetty.xml: jettyPort
<!-- update -->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="slave"
dataDirectory="${activemq.data}">
<!-- update à
<managementContext>
<managementContext createConnector="true" connectorPort="2099"/>
</managementContext>
<!-- update à
<persistenceAdapter>
<kahaDB directory="<<your location>>"/cluster/data"/>
</persistenceAdapter>
<!-- add-->
<networkConnectors>
<networkConnector uri="static:(tcp://localhost:61616)"/>
</networkConnectors>
<!– update – also remove other transports à
<transportConnector name="openwire"
uri="tcp://0.0.0.0:61617?maximumConnections=1000&wireFormat.maxFrameSiz
e=104857600"/>
<property name="port" value="8162"/>
34. ActiveMQ High Availability Demo
6. Start the Master and then the Slave Broker
7. Open Master Web Console – Queues Page
8. Create a Queue and Send a Message
9. Stop the Master Broker
10. Open Slave Web Console – Queues Page
11. View the Queue and persisted Message
cd ../cluster/<<master || slave>>/bin
./activemq start OR ./activemq.bat
Open http://localhost:8161/admin/ {admin/admin}
Open http://localhost:8161/admin/queues.jsp
Open http://localhost:8162/admin/ {admin/admin}
Open http://localhost:8162/admin/queues.jsp
cd ../cluster/<<master || slave>>/bin
./activemq stop OR Ctrl+C
35. ActiveMQ Federated Topology Example
Linux VM
Queue
<Execution Environment>
ActiveMQ (Master)
Topic
Linux VM
Queue
<Execution Environment>
ActiveMQ (Slave)
Topic
<NFS Mount>
Kaha DB
Linux VM
Queue
<Execution Environment>
ActiveMQ (Master)
Topic
Linux VM
Queue
<Execution Environment>
ActiveMQ (Slave)
Topic
<NFS Mount>
Kaha DB
Linux VM
Queue
<Execution Environment>
ActiveMQ (Master)
Topic
Linux VM
Queue
<Execution Environment>
ActiveMQ (Slave)
Topic
<NFS Mount>
Kaha DB
Web Network Segment
Service Network Segment
Data Network Segment
46. Exercise: Content Based Routing - Docker
1. Build Camel Standalone Router Docker Compose
2. Start Camel Standalone Router Docker
3. Execute Test
4. View Messages from ActiveMQ or Hawtio (priority.order)
5. View Magic Supplies log for orders processed (magic.order)
docker compose up
Open http://localhost:8161/admin/ {admin/admin}
Open http://localhost:8161/admin/queues.jsp
mvn clean install
docker-compose build
http://localhost:9999/message/emagic.orders
Stop existing Docker-Compose Message Client
47. Hawtio connect to Camel- Docker
1. Open in Browser
2. Connect Remote to Camel
http://localhost:8090/hawtio
endpoints.jolokia.sensitive=falseapplication.properties
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
<version>1.3.7</version>
</dependency>
pom.xml
48. Camel Unit Testing
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
//setup routes to Mock Endpoints
context.addRoutes(new RouteBuilder() {
public void configure() {
//test xpath split
from ("direct:split").
split(new XPathBuilder (MagicRouteBuilder.splitXpath)).
to("mock:order");
});
return context;
}
@Test
public void testSplitLogic() throws Exception {
//Set expectations
MockEndpoint order = getMockEndpoint("mock:order");
order.expectedMessageCount(3);
//read in a small batch
String xml = IOUtils.toString(this.getClass().
getResourceAsStream("batch.xml"), "UTF-8");
//execute the test
template.sendBody("direct:split", xml);
//should be three orders in the batch
order.assertIsSatisfied();
}
MagicRouteBuilderTest.java
49. Camel Functional Testing
1. Download and install Apache JMeter
2. Copy $ACTIVEMQ_HOME/activemq-all-5.13.1.jar to $JMETER_HOME/lib
3. Start JMeter - ./jmeter.sh or jmeter.bat
4. Open camel-magic-router/src/test/jmeter/Mock Camel Publisher.jmx
5. Run test
Other possible frameworks
• RobotFramework
• SOAPUI
58. Exercise: Enrichment and Transformation - Docker
1. Build Camel Standalone Router Docker Compose
2. Start Camel Standalone Router Docker
3. Execute Test
4. View Message from ActiveMQ or hawtio (priority.order)
5. View Magic Supplies log for orders processed
docker compose up
Open http://localhost:8161/admin/ {admin/admin}
Open http://localhost:8161/admin/queues.jsp
mvn clean install
docker-compose build
http://localhost:9999/message/emagic.orders
59. Exercise: Wire-Tap
1. Replace Routing w/: Wire-Tap to Splitter and Evaluation Route
2. Stop Spring Boot, Build Project, and Start Spring Boot
3. Execute Message Client & View Results
from("activemq:emagic.order").
wireTap("direct:ministry").
to("activemq:magic.order");
from("direct:ministry").
choice().
when().simple("${in.body} contains 'Elder'").
log("ILLEGAL MAGIC ALERT").
to("activemq:topic:magic.alerts").
otherwise().
log("...off into the ether");
mvn clean install
mvn spring-boot:run OR
java –jar ./target/camel-standalone-router-1.0.0.jar
java -jar message-client-1.0.0.jar emagic.orders
Open http://localhost:8161/admin/queues.jsp
Open http://localhost:8161/admin/topics.jsp Wire Ttap
60. Exercise: Wire-Tap - Docker
1. Replace Routing w/: Wire-Tap to Splitter and Evaluation Route
Wire Ttap
from("activemq:emagic.order").
wireTap("direct:ministry").
to("activemq:magic.order");
from("direct:ministry").
choice().
when().simple("${in.body} contains 'Elder'").
log("ILLEGAL MAGIC ALERT").
to("activemq:topic:magic.alerts").
otherwise().
log("...off into the ether");
61. Exercise: Wire-Tap- Docker
1. Build Camel Standalone Router Docker Compose
2. Start Camel Standalone Router Docker
3. Execute Test
4. View Messages from ActiveMQ or hawtio
docker compose up
Open http://localhost:8161/admin/ {admin/admin}
Open http://localhost:8161/admin/queues.jsp
Open http://localhost:8161/admin/topics.jsp
mvn clean install
docker-compose build
http://localhost:9999/message/emagic.orders
Wire Ttap
62. Bonus Exercise: Idempotent Consumer (In-Memory)
?
Idempotent Consumer
1. View IdempotentConsumerRouteBuilder in Camel-Standalone-
Router
2. Start Camel-Standalone Router
3. Execute Message Client
4. Open ActiveMQ Web Console (or view via hawtio)
5. View Magic Supplies log for orders processed (magic.order)
• Only two of three sent messages should be present.
mvn spring-boot:run OR
java –jar ./target/camel-standalone-router-1.0.0.jar
java -jar message-client-1.0.0.jar unique.orders
65. Bonus Exercise*: Idempotent Consumer (Redis)
1. Update IdempotentConsumerRouteBuilder – Comment:
2. Update IdempotentConsumerRouteBuilder - Uncomment
3. Stop Spring Boot, Build Project, and Start Spring Boot
from("activemq:unique.order").
idempotentConsumer(header("uniqueId"),
MemoryIdempotentRepository.memoryIdempotentRepository(200)).
to("activemq:magic.order");
..
@AutowiredRedisTemplate<String, String> redisTemplate;
..
from("activemq:unique.order").
idempotentConsumer(header("uniqueId"),
RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, "camel-repo")).
to("activemq:magic.order");
mvn clean install
mvn spring-boot:run OR
java –jar ./target/camel-standalone-router-1.0.0.jar
*LOCAL ONLY – But for Spring-Redis-Docker See: https://github.com/jtdeane/magic-batch
66. Bonus Exercise *: Idempotent Consumer (Redis)
?
Idempotent Consumer
1. Execute Message Client
2. Open ActiveMQ Web Console (or view via hawtio)
3. View Magic Supplies log for orders processed (magic.order)
• Only two of three sent messages should be present.
java -jar message-client-1.0.0.jar unique.orders
*LOCAL ONLY – But for Spring-Redis-Docker See: https://github.com/jtdeane/magic-batch