└── examples ├── src ├── main │ ├── python │ │ ├── test.py │ │ ├── consumer.py │ │ ├── book.py │ │ └── stocks.py │ ├── resources │ │ └── org │ │ │ └── apache │ │ │ └── activemq │ │ │ └── book │ │ │ ├── ch5 │ │ │ ├── users.properties │ │ │ ├── groups.properties │ │ │ ├── login.config │ │ │ ├── activemq-policy.xml │ │ │ ├── activemq-jaas.xml │ │ │ ├── activemq-custom.xml │ │ │ ├── activemq-simple.xml │ │ │ └── activemq-authorization.xml │ │ │ ├── ch4 │ │ │ ├── mybroker.ks │ │ │ ├── myclient.ks │ │ │ ├── myclient.ts │ │ │ ├── mybroker_cert │ │ │ ├── brokerB.xml │ │ │ ├── activemq-multicast.xml │ │ │ ├── activemq-ssl.xml │ │ │ └── brokerA.xml │ │ │ ├── ch6 │ │ │ ├── groups.properties │ │ │ ├── mybroker.ts │ │ │ ├── consumer_cert │ │ │ ├── myconsumer.ks │ │ │ ├── myproducer.ks │ │ │ ├── producer_cert │ │ │ ├── users.properties │ │ │ ├── spring-1.0.xml │ │ │ ├── login.config │ │ │ ├── activemq-jaas.xml │ │ │ ├── activemq-policy.xml │ │ │ ├── activemq-custom.xml │ │ │ ├── spring-2.0.xml │ │ │ ├── activemq-simple.xml │ │ │ └── activemq-authorization.xml │ │ │ ├── ch7 │ │ │ ├── spring-1.0.xml │ │ │ ├── spring-2.0.xml │ │ │ ├── pure-spring.xml │ │ │ └── spring-client.xml │ │ │ ├── ch2 │ │ │ ├── customer-info.txt │ │ │ └── activemq.xml │ │ │ ├── ch11 │ │ │ ├── broker.xml │ │ │ └── camel.xml │ │ │ ├── ch14 │ │ │ ├── log4j.properties │ │ │ ├── activemq-jmx.xml │ │ │ └── activemq-advisory.xml │ │ │ ├── ch9 │ │ │ └── activemq-stomp.xml │ │ │ ├── ch8 │ │ │ └── jndi.properties │ │ │ └── ch10 │ │ │ └── scalingconfig.xml │ ├── java │ │ ├── org │ │ │ └── apache │ │ │ │ └── activemq │ │ │ │ └── book │ │ │ │ ├── ch6 │ │ │ │ ├── broker │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Factory.java │ │ │ │ │ └── Broker.java │ │ │ │ ├── spring │ │ │ │ │ ├── SpringClient.java │ │ │ │ │ ├── SpringBroker.java │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── StockMessageCreator.java │ │ │ │ │ └── SpringPublisher.java │ │ │ │ ├── IPAuthenticationPlugin.java │ │ │ │ ├── AuthorizationPolicy.java │ │ │ │ ├── readme.txt │ │ │ │ ├── IPAuthenticationBroker.java │ │ │ │ └── Consumer.java │ │ │ │ ├── ch2 │ │ │ │ ├── jobs │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Listener.java │ │ │ │ │ └── Consumer.java │ │ │ │ └── portfolio │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Listener.java │ │ │ │ │ └── Consumer.java │ │ │ │ ├── ch3 │ │ │ │ ├── jobs │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Listener.java │ │ │ │ │ └── Consumer.java │ │ │ │ ├── portfolio │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Listener.java │ │ │ │ │ └── Consumer.java │ │ │ │ └── Consumer.java │ │ │ │ ├── ch7 │ │ │ │ ├── xbean │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── Factory.java │ │ │ │ │ ├── XBeanBroker.java │ │ │ │ │ └── Broker.java │ │ │ │ └── spring │ │ │ │ │ ├── SpringClient.java │ │ │ │ │ ├── BrokerFactoryBeanExample.java │ │ │ │ │ ├── readme.txt │ │ │ │ │ ├── StockMessageCreator.java │ │ │ │ │ └── SpringPublisher.java │ │ │ │ ├── ch14 │ │ │ │ ├── advisory │ │ │ │ │ ├── NoConsumerAdvisoryListener.java │ │ │ │ │ ├── ConsumerAdvisoryListener.java │ │ │ │ │ ├── Test.java │ │ │ │ │ └── Advisory.java │ │ │ │ └── jmx │ │ │ │ │ ├── Listener.java │ │ │ │ │ ├── Test.java │ │ │ │ │ ├── Consumer.java │ │ │ │ │ └── Stats.java │ │ │ │ ├── ch4 │ │ │ │ ├── MemoryStoreEmbeddedBroker.java │ │ │ │ ├── RetroactiveConsumer.java │ │ │ │ ├── AMQStoreEmbeddedBroker.java │ │ │ │ ├── Consumer.java │ │ │ │ └── KahaDBEmbeddedBroker.java │ │ │ │ ├── ch5 │ │ │ │ ├── IPAuthenticationPlugin.java │ │ │ │ ├── AuthorizationPolicy.java │ │ │ │ ├── readme.txt │ │ │ │ ├── IPAuthenticationBroker.java │ │ │ │ └── Consumer.java │ │ │ │ └── ch11 │ │ │ │ └── RetroactiveConsumer.java │ │ └── log4j.properties │ ├── php │ │ ├── consumer.php │ │ ├── transactions_send.php │ │ ├── transactions_receive.php │ │ └── durable.php │ ├── ruby │ │ └── consumer.rb │ ├── C# │ │ └── Consumer.cs │ ├── perl │ │ └── consumer.pl │ └── assembly │ │ └── activemq-in-action-src.xml └── test │ └── java │ └── org │ └── apache │ └── activemq │ └── book │ ├── ch11 │ └── CamelConfigTest.java │ └── ch10 │ └── ScalingBrokerConfigTest.java └── chapter8 ├── jms-webapp-jboss ├── src │ ├── main │ │ ├── webapp │ │ │ ├── META-INF │ │ │ │ ├── MANIFEST.MF │ │ │ │ └── context.xml │ │ │ ├── index.jsp │ │ │ └── WEB-INF │ │ │ │ ├── jsp │ │ │ │ ├── include.jsp │ │ │ │ └── send.jsp │ │ │ │ ├── jboss-web.xml │ │ │ │ ├── jms-webapp-servlet.xml │ │ │ │ └── web.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── activemq │ │ │ │ └── book │ │ │ │ └── ch8 │ │ │ │ └── jms │ │ │ │ ├── delegate │ │ │ │ └── JmsMessageDelegate.java │ │ │ │ ├── domain │ │ │ │ └── JmsMessage.java │ │ │ │ ├── service │ │ │ │ └── JmsMessageSenderService.java │ │ │ │ └── web │ │ │ │ └── controller │ │ │ │ └── JmsMessageSenderController.java │ │ └── resources │ │ │ └── activemq.xml │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── activemq │ │ └── book │ │ └── ch8 │ │ └── web │ │ └── JmsDemoControllerTest.java ├── .springBeans ├── .classpath └── .project ├── jms-webapp-local ├── src │ ├── main │ │ ├── webapp │ │ │ ├── META-INF │ │ │ │ ├── MANIFEST.MF │ │ │ │ └── context.xml │ │ │ ├── index.jsp │ │ │ └── WEB-INF │ │ │ │ ├── jsp │ │ │ │ ├── include.jsp │ │ │ │ └── send.jsp │ │ │ │ ├── jms-webapp-servlet.xml │ │ │ │ └── web.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── activemq │ │ │ │ └── book │ │ │ │ └── ch8 │ │ │ │ └── jms │ │ │ │ ├── delegate │ │ │ │ └── JmsMessageDelegate.java │ │ │ │ ├── domain │ │ │ │ └── JmsMessage.java │ │ │ │ ├── service │ │ │ │ └── JmsMessageSenderService.java │ │ │ │ └── web │ │ │ │ └── controller │ │ │ │ └── JmsMessageSenderController.java │ │ └── resources │ │ │ └── activemq.xml │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── activemq │ │ └── book │ │ └── ch8 │ │ └── web │ │ └── JmsDemoControllerTest.java ├── .springBeans ├── .classpath └── .project ├── jms-webapp-geronimo ├── src │ ├── main │ │ ├── webapp │ │ │ ├── META-INF │ │ │ │ ├── MANIFEST.MF │ │ │ │ └── context.xml │ │ │ ├── index.jsp │ │ │ └── WEB-INF │ │ │ │ ├── jsp │ │ │ │ ├── include.jsp │ │ │ │ └── send.jsp │ │ │ │ ├── geronimo-web.xml │ │ │ │ ├── jms-webapp-servlet.xml │ │ │ │ └── web.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── apache │ │ │ │ └── activemq │ │ │ │ └── book │ │ │ │ └── ch8 │ │ │ │ └── jms │ │ │ │ ├── delegate │ │ │ │ └── JmsMessageDelegate.java │ │ │ │ ├── domain │ │ │ │ └── JmsMessage.java │ │ │ │ ├── service │ │ │ │ └── JmsMessageSenderService.java │ │ │ │ └── web │ │ │ │ └── controller │ │ │ │ └── JmsMessageSenderController.java │ │ └── resources │ │ │ └── activemq.xml │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── activemq │ │ └── book │ │ └── ch8 │ │ └── web │ │ └── JmsDemoControllerTest.java ├── .springBeans ├── .classpath └── .project ├── jms-webapp-global ├── src │ ├── main │ │ ├── webapp │ │ │ ├── index.jsp │ │ │ └── WEB-INF │ │ │ │ ├── jsp │ │ │ │ ├── include.jsp │ │ │ │ └── send.jsp │ │ │ │ ├── jms-webapp-servlet.xml │ │ │ │ ├── jetty-env.xml │ │ │ │ ├── web.xml │ │ │ │ └── spring │ │ │ │ └── jms-context.xml │ │ └── java │ │ │ └── org │ │ │ └── apache │ │ │ └── activemq │ │ │ └── book │ │ │ └── ch8 │ │ │ └── jms │ │ │ ├── delegate │ │ │ └── JmsMessageDelegate.java │ │ │ ├── domain │ │ │ └── JmsMessage.java │ │ │ ├── service │ │ │ └── JmsMessageSenderService.java │ │ │ └── web │ │ │ └── controller │ │ │ └── JmsMessageSenderController.java │ └── test │ │ └── java │ │ └── org │ │ └── apache │ │ └── activemq │ │ └── book │ │ └── ch8 │ │ └── web │ │ └── JmsDemoControllerTest.java ├── .classpath ├── .project └── activemq.xml └── pom.xml /examples/src/main/python/test.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/users.properties: -------------------------------------------------------------------------------- 1 | admin=password 2 | publisher=password 3 | consumer=password 4 | guest=password -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | 3 | <% response.sendRedirect("send.html"); %> 4 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | 3 | <% response.sendRedirect("send.html"); %> 4 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | 3 | <% response.sendRedirect("send.html"); %> 4 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/groups.properties: -------------------------------------------------------------------------------- 1 | admins=admin 2 | publishers=admin,publisher 3 | consumers=admin,publisher,consumer 4 | guests=guest -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/mybroker.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch4/mybroker.ks -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/myclient.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch4/myclient.ks -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/myclient.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch4/myclient.ts -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/groups.properties: -------------------------------------------------------------------------------- 1 | admins=admin 2 | publishers=admin,publisher,sslpublisher 3 | consumers=admin,publisher,consumer,sslconsumer 4 | guests=guest -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/mybroker.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch6/mybroker.ts -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/mybroker_cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch4/mybroker_cert -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/consumer_cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch6/consumer_cert -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/myconsumer.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch6/myconsumer.ks -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/myproducer.ks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch6/myproducer.ks -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/producer_cert: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bsnyder/activemq-in-action/HEAD/examples/src/main/resources/org/apache/activemq/book/ch6/producer_cert -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/broker/readme.txt: -------------------------------------------------------------------------------- 1 | - Broker.java demonstrates how to use BrokerService 2 | - Factory.java demonstrates how to instantiate broker from predefined xml configuration -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | <%--@ include file="/WEB-INF/jsp/include.jsp" --%> 3 | 4 | <% response.sendRedirect("send.html"); %> -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/jobs/readme.txt: -------------------------------------------------------------------------------- 1 | 1. Start ActiveMQ: ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch2/activemq.xml 2 | 2. Run Publisher class 3 | 3. Run Consumer class -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/jobs/readme.txt: -------------------------------------------------------------------------------- 1 | 1. Start ActiveMQ: ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch2/activemq.xml 2 | 2. Run Publisher class 3 | 3. Run Consumer class -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/login.config: -------------------------------------------------------------------------------- 1 | activemq-domain { 2 | org.apache.activemq.jaas.PropertiesLoginModule required 3 | debug=true 4 | org.apache.activemq.jaas.properties.user="users.properties" 5 | org.apache.activemq.jaas.properties.group="groups.properties"; 6 | }; -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/portfolio/readme.txt: -------------------------------------------------------------------------------- 1 | 1. Start ActiveMQ: ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch2/activemq.xml 2 | 2. Run Publisher class with desired stock as parameters (e.g. IONA JAVA) 3 | 3. Run Consumer class with desired stock as parameters (e.g. IONA JAVA) -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/portfolio/readme.txt: -------------------------------------------------------------------------------- 1 | 1. Start ActiveMQ: ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch2/activemq.xml 2 | 2. Run Publisher class with desired stock as parameters (e.g. IONA JAVA) 3 | 3. Run Consumer class with desired stock as parameters (e.g. IONA JAVA) -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/users.properties: -------------------------------------------------------------------------------- 1 | admin=password 2 | publisher=password 3 | consumer=password 4 | guest=password 5 | sslconsumer=CN=consumer, OU=Chapter 6, O=ActiveMQ in Action, L=Belgrade, ST=Unknown, C=RS 6 | sslpublisher=CN=producer, OU=Chapter 6, O=ActiveMQ in Action, L=Belgrade, ST=Unknown, C=RS -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/xbean/readme.txt: -------------------------------------------------------------------------------- 1 | - Broker.java demonstrates how to start a broker using Java via the BrokerService class 2 | - Factory.java demonstrates how to start a broker using Java via the BrokerFactory class 3 | - SpringConfig.java demonstrates how to start a broker using a pure Spring configuration via the BrokerService class -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/spring-1.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch7/spring-1.0.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/WEB-INF/jsp/include.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 6 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/jsp/include.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 6 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/WEB-INF/jsp/include.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 6 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/WEB-INF/jsp/include.jsp: -------------------------------------------------------------------------------- 1 | <%@ page session="false"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 4 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 5 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 6 | -------------------------------------------------------------------------------- /examples/src/main/java/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, stdout 2 | log4j.logger.org.apache.activemq.spring=WARN 3 | log4j.logger.org.springframework=WARN 4 | log4j.logger.org.apache.xbean.spring=WARN 5 | 6 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 | log4j.appender.stdout.layout.ConversionPattern=%-5p %-30.30c{1} - %m%n 9 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/java/org/apache/activemq/book/ch8/jms/delegate/JmsMessageDelegate.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.delegate; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | /** 6 | * 7 | * @author bsnyder 8 | * 9 | */ 10 | public class JmsMessageDelegate { 11 | 12 | private static final Logger LOG = Logger.getLogger(JmsMessageDelegate.class); 13 | 14 | public void handleMessage(String message) { 15 | LOG.info("Consumed message with payload: " + message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/java/org/apache/activemq/book/ch8/jms/delegate/JmsMessageDelegate.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.delegate; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | /** 6 | * 7 | * @author bsnyder 8 | * 9 | */ 10 | public class JmsMessageDelegate { 11 | 12 | private static final Logger LOG = Logger.getLogger(JmsMessageDelegate.class); 13 | 14 | public void handleMessage(String message) { 15 | LOG.info("Consumed message with payload: " + message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/java/org/apache/activemq/book/ch8/jms/delegate/JmsMessageDelegate.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.delegate; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | /** 6 | * 7 | * @author bsnyder 8 | * 9 | */ 10 | public class JmsMessageDelegate { 11 | 12 | private static final Logger LOG = Logger.getLogger(JmsMessageDelegate.class); 13 | 14 | public void handleMessage(String message) { 15 | LOG.info("Consumed message with payload: " + message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/java/org/apache/activemq/book/ch8/jms/delegate/JmsMessageDelegate.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.delegate; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | /** 6 | * 7 | * @author bsnyder 8 | * 9 | */ 10 | public class JmsMessageDelegate { 11 | 12 | private static final Logger LOG = Logger.getLogger(JmsMessageDelegate.class); 13 | 14 | public void handleMessage(String message) { 15 | LOG.info("Consumed message with payload: " + message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/spring/SpringClient.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.spring; 2 | 3 | import org.apache.xbean.spring.context.FileSystemXmlApplicationContext; 4 | 5 | 6 | public class SpringClient { 7 | 8 | public static void main(String[] args) { 9 | FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("src/main/resources/org/apache/activemq/book/ch6/spring-client.xml"); 10 | SpringPublisher publisher = (SpringPublisher)context.getBean("stockPublisher"); 11 | publisher.start(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/login.config: -------------------------------------------------------------------------------- 1 | activemq-domain { 2 | org.apache.activemq.jaas.PropertiesLoginModule required 3 | debug=true 4 | org.apache.activemq.jaas.properties.user="users.properties" 5 | org.apache.activemq.jaas.properties.group="groups.properties"; 6 | }; 7 | 8 | activemq-certificate { 9 | org.apache.activemq.jaas.TextFileCertificateLoginModule required 10 | debug=true 11 | org.apache.activemq.jaas.textfiledn.user="users.properties" 12 | org.apache.activemq.jaas.textfiledn.group="groups.properties"; 13 | }; -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/webapp/WEB-INF/spring/jms-context.xml 11 | src/main/webapp/WEB-INF/jms-webapp-servlet.xml 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/webapp/WEB-INF/spring/jms-context.xml 11 | src/main/webapp/WEB-INF/jms-webapp-servlet.xml 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/.springBeans: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | 5 | 6 | 7 | 8 | 9 | 10 | src/main/webapp/WEB-INF/spring/jms-context.xml 11 | src/main/webapp/WEB-INF/jms-webapp-servlet.xml 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/broker/Factory.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.broker; 2 | 3 | import java.net.URI; 4 | 5 | import org.apache.activemq.broker.BrokerFactory; 6 | import org.apache.activemq.broker.BrokerService; 7 | 8 | public class Factory { 9 | 10 | public static void main(String[] args) throws Exception { 11 | System.setProperty("activemq.base", System.getProperty("user.dir")); 12 | BrokerService broker = BrokerFactory.createBroker(new URI("xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml")); 13 | broker.start(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/advisory/NoConsumerAdvisoryListener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.advisory; 2 | 3 | import javax.jms.Message; 4 | import javax.jms.MessageListener; 5 | 6 | import org.apache.activemq.command.ActiveMQMapMessage; 7 | 8 | public class NoConsumerAdvisoryListener implements MessageListener { 9 | 10 | public void onMessage(Message message) { 11 | try { 12 | System.out.println("Message " + ((ActiveMQMapMessage)message).getContentMap() + " not consumed by any consumer"); 13 | } catch (Exception e) { 14 | e.printStackTrace(); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/jobs/Listener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch2.jobs; 2 | 3 | import javax.jms.Message; 4 | import javax.jms.MessageListener; 5 | import javax.jms.ObjectMessage; 6 | 7 | public class Listener implements MessageListener { 8 | 9 | private String job; 10 | 11 | public Listener(String job) { 12 | this.job = job; 13 | } 14 | 15 | public void onMessage(Message message) { 16 | try { 17 | //do something here 18 | System.out.println(job + " id:" + ((ObjectMessage)message).getObject()); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/jobs/Listener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch3.jobs; 2 | 3 | import javax.jms.Message; 4 | import javax.jms.MessageListener; 5 | import javax.jms.ObjectMessage; 6 | 7 | public class Listener implements MessageListener { 8 | 9 | private String job; 10 | 11 | public Listener(String job) { 12 | this.job = job; 13 | } 14 | 15 | public void onMessage(Message message) { 16 | try { 17 | //do something here 18 | System.out.println(job + " id:" + ((ObjectMessage)message).getObject()); 19 | } catch (Exception e) { 20 | e.printStackTrace(); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | /jms-webapp 8 | 9 | 10 | jms/ConnectionFactory 11 | java:jms/ConnectionFactory 12 | 13 | 14 | 15 | jms/FooQueue 16 | jms/FooQueue 17 | 18 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/jmx/Listener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.jmx; 2 | 3 | import javax.jms.Message; 4 | import javax.jms.MessageListener; 5 | import javax.jms.ObjectMessage; 6 | 7 | public class Listener implements MessageListener { 8 | 9 | private String job; 10 | 11 | public Listener(String job) { 12 | this.job = job; 13 | } 14 | 15 | public void onMessage(Message message) { 16 | try { 17 | //do something here 18 | System.out.println(job + " id:" + ((ObjectMessage)message).getObject()); 19 | Thread.sleep(1000); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch4/MemoryStoreEmbeddedBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch4; 2 | 3 | import org.apache.activemq.broker.BrokerService; 4 | 5 | public class MemoryStoreEmbeddedBroker { 6 | 7 | public void createEmbeddedBroker() throws Exception { 8 | 9 | BrokerService broker = new BrokerService(); 10 | //configure the broker to use the Memory Store 11 | broker.setPersistent(false); 12 | 13 | //Add a transport connector 14 | broker.addConnector("tcp://localhost:61616"); 15 | 16 | //now start the broker 17 | broker.start(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/src/main/php/consumer.php: -------------------------------------------------------------------------------- 1 | connect('system', 'manager'); 8 | 9 | $stomp->subscribe("/topic/STOCKS.JAVA"); 10 | $stomp->subscribe("/topic/STOCKS.IONA"); 11 | 12 | $i = 0; 13 | while($i++ < 100) { 14 | 15 | $frame = $stomp->readFrame(); 16 | $xml = new SimpleXMLElement($frame->body); 17 | echo $xml->attributes()->name . "\t" . number_format($xml->price,2) 18 | . "\t" . number_format($xml->offer,2) 19 | . "\t" . ($xml->up == "true"?"up":"down") . "\n"; 20 | $stomp->ack($frame); 21 | 22 | } 23 | 24 | $stomp->disconnect(); 25 | 26 | 27 | ?> 28 | -------------------------------------------------------------------------------- /examples/src/main/python/consumer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import time, sys 4 | from xml.etree.ElementTree import ElementTree, XML 5 | from book import printXml 6 | 7 | import stomp 8 | 9 | class MyListener(object): 10 | def on_error(self, headers, message): 11 | print 'received an error %s' % message 12 | 13 | def on_message(self, headers, message): 14 | printXml(message) 15 | 16 | conn = stomp.Connection() 17 | conn.add_listener(MyListener()) 18 | conn.start() 19 | conn.connect() 20 | 21 | conn.subscribe(destination='/topic/STOCKS.JAVA', ack='auto') 22 | conn.subscribe(destination='/topic/STOCKS.IONA', ack='auto') 23 | 24 | 25 | 26 | 27 | time.sleep(60); 28 | 29 | conn.disconnect() 30 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch2/customer-info.txt: -------------------------------------------------------------------------------- 1 | %% 2 | ssn=123456789 3 | firstName=Fred 4 | surName=Garvin 5 | address1=24680 Lower Wacker Dr. 6 | address2= 7 | city=Chicago 8 | state=IL 9 | postalCode=60601 10 | phone=312.123.4567 11 | email=fred@example.com 12 | %% 13 | ssn=1112223333 14 | firstName=Irwin 15 | surName=Fletcher 16 | address1=66435 S. Pine Rd. 17 | address2=#8 18 | city=Eugene 19 | state=OR 20 | postalCode=97401 21 | phone=541-989-2012 22 | email=fletch@abc123.com 23 | %% 24 | ssn=987654321 25 | firstName=Jeffrey 26 | surName=Lebowski 27 | address1=712 E. Stripe Street 28 | address2=#4 29 | city=Los Angeles 30 | state=CA 31 | postalCode=90007 32 | phone=310 687 5432 33 | email=thedude@foo.com -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch5/IPAuthenticationPlugin.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch5; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.activemq.broker.Broker; 6 | import org.apache.activemq.broker.BrokerPlugin; 7 | 8 | public class IPAuthenticationPlugin implements BrokerPlugin { 9 | 10 | List allowedIPAddresses; 11 | 12 | public Broker installPlugin(Broker broker) throws Exception { 13 | return new IPAuthenticationBroker(broker, allowedIPAddresses); 14 | } 15 | 16 | public List getAllowedIPAddresses() { 17 | return allowedIPAddresses; 18 | } 19 | 20 | public void setAllowedIPAddresses(List allowedIPAddresses) { 21 | this.allowedIPAddresses = allowedIPAddresses; 22 | } 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/IPAuthenticationPlugin.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.activemq.broker.Broker; 6 | import org.apache.activemq.broker.BrokerPlugin; 7 | 8 | public class IPAuthenticationPlugin implements BrokerPlugin { 9 | 10 | List allowedIPAddresses; 11 | 12 | public Broker installPlugin(Broker broker) throws Exception { 13 | return new IPAuthenticationBroker(broker, allowedIPAddresses); 14 | } 15 | 16 | public List getAllowedIPAddresses() { 17 | return allowedIPAddresses; 18 | } 19 | 20 | public void setAllowedIPAddresses(List allowedIPAddresses) { 21 | this.allowedIPAddresses = allowedIPAddresses; 22 | } 23 | 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/src/main/ruby/consumer.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'rubygems' 4 | require 'stomp' 5 | require 'xmlsimple' 6 | 7 | @conn = Stomp::Connection.open 'system', 'manager', 'localhost', 61613, false 8 | @count = 0 9 | 10 | @conn.subscribe "/topic/STOCKS.JAVA", { :ack =>"auto" } 11 | @conn.subscribe "/topic/STOCKS.IONA", { :ack =>"auto" } 12 | while @count < 100 13 | @msg = @conn.receive 14 | @count = @count + 1 15 | if @msg.command == "MESSAGE" 16 | @xml = XmlSimple.xml_in(@msg.body) 17 | $stdout.print "#{@xml['name']}\t" 18 | $stdout.print "#{'%.2f' % @xml['price']}\t" 19 | $stdout.print "#{'%.2f' % @xml['offer']}\t" 20 | $stdout.print "#{@xml['up'].to_s == 'true'?'up':'down'}\n" 21 | else 22 | $stdout.print "#{@msg.command}: #{@msg.body}\n" 23 | end 24 | end 25 | @conn.disconnect -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/spring/SpringClient.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.spring; 2 | 3 | import org.apache.activemq.broker.BrokerService; 4 | import org.apache.xbean.spring.context.FileSystemXmlApplicationContext; 5 | 6 | 7 | public class SpringClient { 8 | 9 | public static void main(String[] args) throws Exception { 10 | BrokerService broker = new BrokerService(); 11 | broker.addConnector("tcp://localhost:61616"); 12 | broker.setPersistent(false); 13 | broker.start(); 14 | 15 | FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("src/main/resources/org/apache/activemq/book/ch7/spring-client.xml"); 16 | SpringPublisher publisher = (SpringPublisher)context.getBean("stockPublisher"); 17 | publisher.start(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /examples/src/main/php/transactions_send.php: -------------------------------------------------------------------------------- 1 | connect(); 8 | 9 | // try to send some messages 10 | $con->begin("tx1"); 11 | for ($i = 1; $i < 3; $i++) { 12 | $con->send("/queue/transactions", $i, array("transaction" => "tx1")); 13 | } 14 | // if we abort transaction, messages will not be sent 15 | $con->abort("tx1"); 16 | 17 | // now send some messages for real 18 | $con->begin("tx2"); 19 | echo "Sent messages {\n"; 20 | for ($i = 1; $i < 5; $i++) { 21 | $con->send("/queue/transactions", $i, array("transaction" => "tx2")); 22 | echo "\t$i\n"; 23 | } 24 | echo "}\n"; 25 | // they will be available for consumers after commit 26 | $con->commit("tx2"); 27 | 28 | ?> -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/xbean/Factory.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.xbean; 2 | 3 | import java.net.URI; 4 | 5 | import org.apache.activemq.broker.BrokerFactory; 6 | import org.apache.activemq.broker.BrokerService; 7 | 8 | public class Factory { 9 | 10 | public static void main(String[] args) throws Exception { 11 | System.setProperty("activemq.base", System.getProperty("user.dir")); 12 | BrokerService broker = BrokerFactory.createBroker( 13 | new URI("xbean:target/classes/org/apache/activemq/book/ch7/activemq-simple.xml")); 14 | broker.start(); 15 | 16 | System.out.println(); 17 | System.out.println("Press any key to stop the broker"); 18 | System.out.println(); 19 | 20 | System.in.read(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch5/AuthorizationPolicy.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch5; 2 | 3 | import org.apache.activemq.broker.ConnectionContext; 4 | import org.apache.activemq.command.Message; 5 | import org.apache.activemq.security.MessageAuthorizationPolicy; 6 | import org.apache.commons.logging.Log; 7 | import org.apache.commons.logging.LogFactory; 8 | 9 | public class AuthorizationPolicy implements 10 | MessageAuthorizationPolicy { 11 | 12 | private static final Log LOG = LogFactory.getLog(AuthorizationPolicy.class); 13 | 14 | public boolean isAllowedToConsume(ConnectionContext context, Message message) { 15 | LOG.info(context.getConnection().getRemoteAddress()); 16 | if (context.getConnection().getRemoteAddress().startsWith("/127.0.0.1")) { 17 | return true; 18 | } else { 19 | return false; 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/portfolio/Listener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch2.portfolio; 2 | 3 | import java.text.DecimalFormat; 4 | 5 | import javax.jms.MapMessage; 6 | import javax.jms.Message; 7 | import javax.jms.MessageListener; 8 | 9 | public class Listener implements MessageListener { 10 | 11 | public void onMessage(Message message) { 12 | try { 13 | MapMessage map = (MapMessage)message; 14 | String stock = map.getString("stock"); 15 | double price = map.getDouble("price"); 16 | double offer = map.getDouble("offer"); 17 | boolean up = map.getBoolean("up"); 18 | DecimalFormat df = new DecimalFormat( "#,###,###,##0.00" ); 19 | System.out.println(stock + "\t" + df.format(price) + "\t" + df.format(offer) + "\t" + (up?"up":"down")); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/portfolio/Listener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch3.portfolio; 2 | 3 | import java.text.DecimalFormat; 4 | 5 | import javax.jms.MapMessage; 6 | import javax.jms.Message; 7 | import javax.jms.MessageListener; 8 | 9 | public class Listener implements MessageListener { 10 | 11 | public void onMessage(Message message) { 12 | try { 13 | MapMessage map = (MapMessage)message; 14 | String stock = map.getString("stock"); 15 | double price = map.getDouble("price"); 16 | double offer = map.getDouble("offer"); 17 | boolean up = map.getBoolean("up"); 18 | DecimalFormat df = new DecimalFormat( "#,###,###,##0.00" ); 19 | System.out.println(stock + "\t" + df.format(price) + "\t" + df.format(offer) + "\t" + (up?"up":"down")); 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/chapter8/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 11 | org.apache.activemq.book 12 | activemq-in-action-examples-chapter8 13 | pom 14 | 1.0-SNAPSHOT 15 | ActiveMQ In Action Examples Chapter 8 16 | 17 | 18 | jms-webapp-geronimo 19 | jms-webapp-global 20 | jms-webapp-jboss 21 | jms-webapp-local 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch4/RetroactiveConsumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch4; 2 | 3 | import org.apache.activemq.ActiveMQConnectionFactory; 4 | import javax.jms.Connection; 5 | import javax.jms.ConnectionFactory; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | import javax.jms.Topic; 10 | 11 | 12 | public class RetroactiveConsumer { 13 | 14 | public void createRetroactiveConsumer() throws JMSException { 15 | 16 | ConnectionFactory fac = new ActiveMQConnectionFactory(); 17 | Connection connection = fac.createConnection(); 18 | connection.start(); 19 | Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 20 | Topic topic = session.createTopic("TEST.TOPIC?consumer.retroactive=true"); 21 | MessageConsumer consumer = session.createConsumer(topic); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch11/broker.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch14/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, out, stdout 2 | 3 | log4j.logger.org.apache.activemq.spring=WARN 4 | log4j.logger.org.springframework=WARN 5 | log4j.logger.org.apache.xbean.spring=WARN 6 | 7 | log4j.logger.org.apache.activemq.transport.failover.FailoverTransport=DEBUG 8 | log4j.logger.org.apache.activemq.transport.TransportLogger=DEBUG 9 | 10 | # CONSOLE appender not used by default 11 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 12 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 13 | log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n 14 | 15 | # File appender 16 | log4j.appender.out=org.apache.log4j.FileAppender 17 | log4j.appender.out.layout=org.apache.log4j.PatternLayout 18 | log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n 19 | log4j.appender.out.file=target/activemq.log 20 | log4j.appender.out.append=true 21 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/test/java/org/apache/activemq/book/ch8/web/JmsDemoControllerTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.web; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.apache.activemq.book.ch8.jms.web.controller.JmsMessageSenderController; 7 | import org.junit.Test; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | 11 | public class JmsDemoControllerTest { 12 | 13 | @Test 14 | public void testHandleRequestView() throws Exception{ 15 | /* 16 | JmsDemoController controller = new JmsDemoController(); 17 | ModelAndView modelAndView = controller.handleRequest(null, null); 18 | assertEquals("index", modelAndView.getViewName()); 19 | assertNotNull(modelAndView.getModel()); 20 | String nowValue = (String) modelAndView.getModel().get("now"); 21 | assertNotNull(nowValue); 22 | */ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/test/java/org/apache/activemq/book/ch8/web/JmsDemoControllerTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.web; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.apache.activemq.book.ch8.jms.web.controller.JmsMessageSenderController; 7 | import org.junit.Test; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | 11 | public class JmsDemoControllerTest { 12 | 13 | @Test 14 | public void testHandleRequestView() throws Exception{ 15 | /* 16 | JmsDemoController controller = new JmsDemoController(); 17 | ModelAndView modelAndView = controller.handleRequest(null, null); 18 | assertEquals("index", modelAndView.getViewName()); 19 | assertNotNull(modelAndView.getModel()); 20 | String nowValue = (String) modelAndView.getModel().get("now"); 21 | assertNotNull(nowValue); 22 | */ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/test/java/org/apache/activemq/book/ch8/web/JmsDemoControllerTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.web; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.apache.activemq.book.ch8.jms.web.controller.JmsMessageSenderController; 7 | import org.junit.Test; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | 11 | public class JmsDemoControllerTest { 12 | 13 | @Test 14 | public void testHandleRequestView() throws Exception{ 15 | /* 16 | JmsDemoController controller = new JmsDemoController(); 17 | ModelAndView modelAndView = controller.handleRequest(null, null); 18 | assertEquals("index", modelAndView.getViewName()); 19 | assertNotNull(modelAndView.getModel()); 20 | String nowValue = (String) modelAndView.getModel().get("now"); 21 | assertNotNull(nowValue); 22 | */ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/spring/SpringBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.spring; 2 | 3 | import org.apache.activemq.book.ch5.Publisher; 4 | import org.apache.xbean.spring.context.FileSystemXmlApplicationContext; 5 | 6 | 7 | public class SpringBroker { 8 | 9 | public static void main(String[] args) throws Exception { 10 | if (args.length == 0) { 11 | System.err.println("Please define a configuration file!"); 12 | return; 13 | } 14 | String config = args[0]; 15 | System.out.println("Starting broker with the following configuration: " + config); 16 | System.setProperty("activemq.base", System.getProperty("user.dir")); 17 | FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(config); 18 | 19 | Publisher publisher = new Publisher(); 20 | for (int i = 0; i < 100; i++) { 21 | publisher.sendMessage(new String[]{"JAVA", "IONA"}); 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/test/java/org/apache/activemq/book/ch8/web/JmsDemoControllerTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.web; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import org.apache.activemq.book.ch8.jms.web.controller.JmsMessageSenderController; 7 | import org.junit.Test; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | 11 | public class JmsDemoControllerTest { 12 | 13 | @Test 14 | public void testHandleRequestView() throws Exception{ 15 | /* 16 | JmsDemoController controller = new JmsDemoController(); 17 | ModelAndView modelAndView = controller.handleRequest(null, null); 18 | assertEquals("index", modelAndView.getViewName()); 19 | assertNotNull(modelAndView.getModel()); 20 | String nowValue = (String) modelAndView.getModel().get("now"); 21 | assertNotNull(nowValue); 22 | */ 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/AuthorizationPolicy.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6; 2 | 3 | import org.apache.activemq.broker.ConnectionContext; 4 | import org.apache.activemq.command.Message; 5 | import org.apache.activemq.security.MessageAuthorizationPolicy; 6 | import org.apache.commons.logging.Log; 7 | import org.apache.commons.logging.LogFactory; 8 | 9 | public class AuthorizationPolicy implements 10 | MessageAuthorizationPolicy { 11 | 12 | private static final Log LOG = LogFactory.getLog(AuthorizationPolicy.class); 13 | 14 | public boolean isAllowedToConsume(ConnectionContext context, Message message) { 15 | LOG.info(context.getConnection().getRemoteAddress()); 16 | if (context.getConnection().getRemoteAddress().startsWith("/127.0.0.1")) { 17 | LOG.info("Permission to consume granted"); 18 | return true; 19 | } else { 20 | LOG.info("Permission to consume denied"); 21 | return false; 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/WEB-INF/geronimo-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | org.apache.activemq.book 6 | jms-webapp 7 | 1.0-SNAPSHOT 8 | war 9 | 10 | 11 | 12 | 13 | console.jms 14 | FooGroup 15 | 1.0 16 | car 17 | 18 | 19 | 20 | 21 | org.springframework. 22 | META-INF/spring 23 | 24 | 25 | 26 | /jms-webapp 27 | 28 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/spring/BrokerFactoryBeanExample.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.spring; 2 | 3 | import org.apache.activemq.book.ch6.Publisher; 4 | import org.apache.xbean.spring.context.FileSystemXmlApplicationContext; 5 | 6 | 7 | public class BrokerFactoryBeanExample { 8 | 9 | public static void main(String[] args) throws Exception { 10 | if (args.length == 0) { 11 | System.err.println("Please define a configuration file!"); 12 | return; 13 | } 14 | String config = args[0]; 15 | System.out.println("Starting broker with the following configuration: " + config); 16 | System.setProperty("activemq.base", System.getProperty("user.dir")); 17 | FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(config); 18 | 19 | Publisher publisher = new Publisher(); 20 | for (int i = 0; i < 100; i++) { 21 | publisher.sendMessage(new String[]{"JAVA", "IONA"}); 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/WEB-INF/jms-webapp-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/jms-webapp-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/WEB-INF/jms-webapp-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/WEB-INF/jms-webapp-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch4/AMQStoreEmbeddedBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch4; 2 | 3 | import org.apache.activemq.broker.BrokerService; 4 | import org.apache.activemq.store.amq.AMQPersistenceAdapterFactory; 5 | 6 | public class AMQStoreEmbeddedBroker { 7 | 8 | public void createEmbeddedBroker() throws Exception { 9 | 10 | BrokerService broker = new BrokerService(); 11 | //initialize the PersistenceAdaptorFactory 12 | AMQPersistenceAdapterFactory persistenceFactory = new AMQPersistenceAdapterFactory(); 13 | 14 | //set some properties on the factory 15 | persistenceFactory.setMaxFileLength(1024*16); 16 | persistenceFactory.setPersistentIndex(true); 17 | broker.setPersistenceFactory(persistenceFactory); 18 | 19 | //create a transport connector 20 | broker.addConnector("tcp://localhost:61616"); 21 | //start the broker 22 | broker.start(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/src/main/python/book.py: -------------------------------------------------------------------------------- 1 | import random 2 | from xml.etree.ElementTree import Element, SubElement, XML, tostring 3 | 4 | def mutatePrice(price): 5 | MAX_DELTA_PERCENT = 1 6 | percentChange = (2 * random.random() * MAX_DELTA_PERCENT) - MAX_DELTA_PERCENT 7 | 8 | return price * (100 + percentChange) / 100; 9 | 10 | def createXml(oldPrice, price): 11 | stock = Element("stock") 12 | stock.set("name", "JAVA") 13 | priceElem = SubElement(stock, "price") 14 | priceElem.text = str(price) 15 | 16 | offer = SubElement(stock, "offer") 17 | offer.text = str(price * 1.001) 18 | 19 | up = SubElement(stock, "up") 20 | up.text = str(oldPrice > price) 21 | 22 | return stock 23 | 24 | def printXml(text): 25 | xml = XML(text) 26 | 27 | print "%s\t%.2f\t%.2f\t%s" % ( 28 | xml.get("name"), 29 | eval(xml.find("price").text), 30 | eval(xml.find("offer").text), 31 | "up" if xml.find("up").text == "True" else "down" 32 | ) 33 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch2/activemq.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/brokerB.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/src/main/C#/Consumer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Apache.NMS; 3 | using Apache.NMS.Util; 4 | using Apache.NMS.ActiveMQ; 5 | 6 | namespace Apache.NMS.ActiveMQ.Book.Ch8 7 | { 8 | public class Consumer 9 | { 10 | public static void Main(string[] args) 11 | { 12 | NMSConnectionFactory NMSFactory = new NMSConnectionFactory("tcp://localhost:61616"); 13 | IConnection connection = NMSFactory.CreateConnection(); 14 | ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); 15 | IDestination destination = session.GetTopic("STOCKS.JAVA"); 16 | IMessageConsumer consumer = session.CreateConsumer(destination); 17 | consumer.Listener += new MessageListener(OnMessage); 18 | connection.Start(); 19 | Console.WriteLine("Press any key to quit."); 20 | Console.ReadKey(); 21 | } 22 | 23 | protected static void OnMessage(IMessage message) 24 | { 25 | ITextMessage TextMessage = message as ITextMessage; 26 | Console.WriteLine(TextMessage.Text); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/src/main/perl/consumer.pl: -------------------------------------------------------------------------------- 1 | use Net::Stomp; 2 | use XML::Simple; 3 | 4 | 5 | 6 | my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } ); 7 | $stomp->connect( { login => 'system', passcode => 'manager' } ); 8 | 9 | $stomp->subscribe( 10 | { destination => '/topic/STOCKS.JAVA', 11 | 'ack' => 'client', 12 | 'activemq.prefetchSize' => 1 13 | } 14 | ); 15 | $stomp->subscribe( 16 | { destination => '/topic/STOCKS.IONA', 17 | 'ack' => 'client', 18 | 'activemq.prefetchSize' => 1 19 | } 20 | ); 21 | 22 | 23 | my $count = 0; 24 | 25 | while ($count++ < 100) { 26 | my $frame = $stomp->receive_frame; 27 | my $xml = XMLin($frame->body); 28 | print $xml->{name} . "\t" . sprintf("%.2f", $xml->{price}) . "\t"; 29 | print sprintf("%.2f", $xml->{offer}) . "\t" . ($xml->{up} eq 'true' ? 'up' : 'down') . "\n"; 30 | 31 | $stomp->ack( { frame => $frame } ); 32 | } 33 | 34 | $stomp->disconnect; 35 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/xbean/XBeanBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.xbean; 2 | 3 | import org.apache.activemq.book.ch6.Publisher; 4 | import org.apache.xbean.spring.context.FileSystemXmlApplicationContext; 5 | 6 | public class XBeanBroker { 7 | 8 | public static void main(String[] args) throws Exception { 9 | if (args.length == 0) { 10 | System.err.println("Please define a configuration file!"); 11 | return; 12 | } 13 | String config = args[0]; 14 | System.out.println("Starting broker with the following configuration: " + config); 15 | System.setProperty("activemq.base", System.getProperty("user.dir")); 16 | 17 | FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(config); 18 | 19 | Publisher publisher = new Publisher(); 20 | for (int i = 0; i < 100; i++) { 21 | publisher.sendMessage(new String[]{"JAVA", "IONA"}); 22 | } 23 | 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/META-INF/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/META-INF/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/META-INF/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/java/org/apache/activemq/book/ch8/jms/domain/JmsMessage.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.domain; 2 | 3 | public class JmsMessage { 4 | 5 | private String replyTo; 6 | private int timeToLive; 7 | private boolean persistent; 8 | private String messagePayload; 9 | 10 | public JmsMessage() {} 11 | 12 | public String getReplyTo() { 13 | return replyTo; 14 | } 15 | public void setReplyTo(String replyTo) { 16 | this.replyTo = replyTo; 17 | } 18 | public int getTimeToLive() { 19 | return timeToLive; 20 | } 21 | public void setTimeToLive(int timeToLive) { 22 | this.timeToLive = timeToLive; 23 | } 24 | public boolean isPersistent() { 25 | return persistent; 26 | } 27 | public void setPersistent(boolean persistent) { 28 | this.persistent = persistent; 29 | } 30 | public String getMessagePayload() { 31 | return messagePayload; 32 | } 33 | public void setMessagePayload(String messagePayload) { 34 | this.messagePayload = messagePayload; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/java/org/apache/activemq/book/ch8/jms/domain/JmsMessage.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.domain; 2 | 3 | public class JmsMessage { 4 | 5 | private String replyTo; 6 | private int timeToLive; 7 | private boolean persistent; 8 | private String messagePayload; 9 | 10 | public JmsMessage() {} 11 | 12 | public String getReplyTo() { 13 | return replyTo; 14 | } 15 | public void setReplyTo(String replyTo) { 16 | this.replyTo = replyTo; 17 | } 18 | public int getTimeToLive() { 19 | return timeToLive; 20 | } 21 | public void setTimeToLive(int timeToLive) { 22 | this.timeToLive = timeToLive; 23 | } 24 | public boolean isPersistent() { 25 | return persistent; 26 | } 27 | public void setPersistent(boolean persistent) { 28 | this.persistent = persistent; 29 | } 30 | public String getMessagePayload() { 31 | return messagePayload; 32 | } 33 | public void setMessagePayload(String messagePayload) { 34 | this.messagePayload = messagePayload; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/java/org/apache/activemq/book/ch8/jms/domain/JmsMessage.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.domain; 2 | 3 | public class JmsMessage { 4 | 5 | private String replyTo; 6 | private int timeToLive; 7 | private boolean persistent; 8 | private String messagePayload; 9 | 10 | public JmsMessage() {} 11 | 12 | public String getReplyTo() { 13 | return replyTo; 14 | } 15 | public void setReplyTo(String replyTo) { 16 | this.replyTo = replyTo; 17 | } 18 | public int getTimeToLive() { 19 | return timeToLive; 20 | } 21 | public void setTimeToLive(int timeToLive) { 22 | this.timeToLive = timeToLive; 23 | } 24 | public boolean isPersistent() { 25 | return persistent; 26 | } 27 | public void setPersistent(boolean persistent) { 28 | this.persistent = persistent; 29 | } 30 | public String getMessagePayload() { 31 | return messagePayload; 32 | } 33 | public void setMessagePayload(String messagePayload) { 34 | this.messagePayload = messagePayload; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/java/org/apache/activemq/book/ch8/jms/domain/JmsMessage.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.domain; 2 | 3 | public class JmsMessage { 4 | 5 | private String replyTo; 6 | private int timeToLive; 7 | private boolean persistent; 8 | private String messagePayload; 9 | 10 | public JmsMessage() {} 11 | 12 | public String getReplyTo() { 13 | return replyTo; 14 | } 15 | public void setReplyTo(String replyTo) { 16 | this.replyTo = replyTo; 17 | } 18 | public int getTimeToLive() { 19 | return timeToLive; 20 | } 21 | public void setTimeToLive(int timeToLive) { 22 | this.timeToLive = timeToLive; 23 | } 24 | public boolean isPersistent() { 25 | return persistent; 26 | } 27 | public void setPersistent(boolean persistent) { 28 | this.persistent = persistent; 29 | } 30 | public String getMessagePayload() { 31 | return messagePayload; 32 | } 33 | public void setMessagePayload(String messagePayload) { 34 | this.messagePayload = messagePayload; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/spring/readme.txt: -------------------------------------------------------------------------------- 1 | SpringBroker demonstrates how to configure broker using Spring 1.0, XBean and Spring 2.0 configuration syntax. 2 | 3 | For Spring 1.0 example run: 4 | 5 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch6/spring-1.0.xml" 6 | 7 | For Spring 2.0 example run: 8 | 9 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch6/spring-2.0.xml" 10 | 11 | For XBean example run: 12 | 13 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml" 14 | 15 | 16 | SpringClient demonstrates how to use Spring JMS support to connect to the ActiveMQ broker. Run it with: 17 | 18 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringClient 19 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/spring/readme.txt: -------------------------------------------------------------------------------- 1 | SpringBroker demonstrates how to configure broker using Spring 1.0, XBean and Spring 2.0 configuration syntax. 2 | 3 | For Spring 1.0 example run: 4 | 5 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch6/spring-1.0.xml" 6 | 7 | For Spring 2.0 example run: 8 | 9 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch6/spring-2.0.xml" 10 | 11 | For XBean example run: 12 | 13 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringBroker -Dlog4j.configuration=file:src/main/java/log4j.properties -Dexec.args="src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml" 14 | 15 | 16 | SpringClient demonstrates how to use Spring JMS support to connect to the ActiveMQ broker. Run it with: 17 | 18 | mvn exec:java -Dexec.mainClass=org.apache.activemq.book.ch6.spring.SpringClient 19 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch9/activemq-stomp.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/activemq-multicast.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/activemq-ssl.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch4/brokerA.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch5/readme.txt: -------------------------------------------------------------------------------- 1 | For Simple authentication plugin example start ActiveMQ with: 2 | ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml 3 | 4 | For JAAS authentication example start ActiveMQ with: 5 | ${ACTIVEMQ_HOME}/bin/activemq -Djava.security.auth.login.config=src/main/resources/org/apache/activemq/book/ch5/login.config xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-jaas.xml 6 | 7 | For authorization example start ActiveMQ with: 8 | ${ACTIVEMQ_HOME}/bin/activemq -Djava.security.auth.login.config=src/main/resources/org/apache/activemq/book/ch5/login.config xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-authorization.xml 9 | 10 | For message authorization policy: 11 | 12 | 1. mvn install 13 | 2. cp target/book-1.0-SNAPSHOT.jar ${ACTIVEMQ_HOME}/lib/ 14 | 3. ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-messagepolicy.xml 15 | 16 | For developing customized plugin: 17 | 1. mvn install 18 | 2. cp target/book-1.0-SNAPSHOT.jar ${ACTIVEMQ_HOME}/lib/ 19 | 3. ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-custom.xml -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/readme.txt: -------------------------------------------------------------------------------- 1 | For Simple authentication plugin example start ActiveMQ with: 2 | ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml 3 | 4 | For JAAS authentication example start ActiveMQ with: 5 | ${ACTIVEMQ_HOME}/bin/activemq -Djava.security.auth.login.config=src/main/resources/org/apache/activemq/book/ch5/login.config xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-jaas.xml 6 | 7 | For authorization example start ActiveMQ with: 8 | ${ACTIVEMQ_HOME}/bin/activemq -Djava.security.auth.login.config=src/main/resources/org/apache/activemq/book/ch5/login.config xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-authorization.xml 9 | 10 | For message authorization policy: 11 | 12 | 1. mvn install 13 | 2. cp target/book-1.0-SNAPSHOT.jar ${ACTIVEMQ_HOME}/lib/ 14 | 3. ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-messagepolicy.xml 15 | 16 | For developing customized plugin: 17 | 1. mvn install 18 | 2. cp target/book-1.0-SNAPSHOT.jar ${ACTIVEMQ_HOME}/lib/ 19 | 3. ${ACTIVEMQ_HOME}/bin/activemq xbean:src/main/resources/org/apache/activemq/book/ch5/activemq-custom.xml -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/jmx/Test.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.jmx; 2 | 3 | import java.util.Set; 4 | 5 | import javax.management.MBeanServerConnection; 6 | import javax.management.ObjectName; 7 | import javax.management.remote.JMXConnector; 8 | import javax.management.remote.JMXConnectorFactory; 9 | import javax.management.remote.JMXServiceURL; 10 | 11 | public class Test { 12 | 13 | /** 14 | * @param args 15 | */ 16 | public static void main(String[] args) throws Exception { 17 | JMXServiceURL url = new JMXServiceURL( 18 | "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"); 19 | JMXConnector connector = JMXConnectorFactory.connect(url, null); 20 | connector.connect(); 21 | MBeanServerConnection connection = connector.getMBeanServerConnection(); 22 | String brokerName = "localhost"; 23 | String connectionName = "ID_dejan-bosanacs-macbook-pro.local-50462-1236596709533-3_0"; 24 | ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" 25 | + brokerName + ",Type=Connection,*,Connection=" 26 | + connectionName); 27 | Set queryResult = connection.queryNames(query, null); 28 | System.out.println(queryResult); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch14/activemq-jmx.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/jetty-env.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | jms/ConnectionFactory 11 | 12 | 13 | vm://localhost?brokerConfig=xbean:activemq.xml 14 | 15 | 16 | 17 | 18 | 19 | jms/FooQueue 20 | 21 | 22 | FOO.QUEUE 23 | 24 | 25 | 26 | 27 | 28 | jms/FooTopic 29 | 30 | 31 | FOO.TOPIC 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/activemq-jaas.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/src/main/python/stocks.py: -------------------------------------------------------------------------------- 1 | import pyactivemq, time, sys, random 2 | from pyactivemq import ActiveMQConnectionFactory 3 | from book import mutatePrice, printXml, createXml 4 | from xml.etree.ElementTree import Element, SubElement, XML, tostring 5 | 6 | class MessageListener(pyactivemq.MessageListener): 7 | 8 | def onMessage(self, message): 9 | printXml(message.text) 10 | 11 | nmessages = 100 12 | 13 | brokerUrl = 'tcp://localhost:61616?wireFormat=openwire' 14 | 15 | if(len(sys.argv) == 2 and sys.argv[1] == 'stomp'): 16 | brokerUrl = 'tcp://localhost:61613?wireFormat=stomp' 17 | 18 | print 'connecting to: ', brokerUrl 19 | 20 | f = ActiveMQConnectionFactory(brokerUrl) 21 | conn = f.createConnection() 22 | 23 | session = conn.createSession() 24 | topic = session.createQueue('stocks') 25 | producer = session.createProducer(topic) 26 | 27 | consumer = session.createConsumer(topic) 28 | consumer.messageListener = MessageListener() 29 | 30 | conn.start() 31 | 32 | textMessage = session.createTextMessage() 33 | price = random.uniform(1, 100) 34 | 35 | for i in xrange(nmessages): 36 | oldPrice = price 37 | price = mutatePrice(price) 38 | 39 | textMessage.text = tostring(createXml(oldPrice, price)) 40 | producer.send(textMessage) 41 | 42 | time.sleep(5) 43 | 44 | conn.close() 45 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/activemq-policy.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/activemq-policy.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch14/activemq-advisory.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/activemq-jaas.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/activemq-custom.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 127.0.0.1 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch5/IPAuthenticationBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch5; 2 | 3 | import java.util.List; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | import org.apache.activemq.broker.Broker; 8 | import org.apache.activemq.broker.BrokerFilter; 9 | import org.apache.activemq.broker.ConnectionContext; 10 | import org.apache.activemq.command.ConnectionInfo; 11 | 12 | public class IPAuthenticationBroker extends BrokerFilter { 13 | 14 | List allowedIPAddresses; 15 | Pattern pattern = Pattern.compile("^/([0-9\\.]*):(.*)"); 16 | 17 | public IPAuthenticationBroker(Broker next, List allowedIPAddresses) { 18 | super(next); 19 | this.allowedIPAddresses = allowedIPAddresses; 20 | } 21 | 22 | public void addConnection(ConnectionContext context, 23 | ConnectionInfo info) throws Exception { 24 | 25 | String remoteAddress = context.getConnection().getRemoteAddress(); 26 | 27 | Matcher matcher = pattern.matcher(remoteAddress); 28 | if (matcher.matches()) { 29 | String ip = matcher.group(1); 30 | if (!allowedIPAddresses.contains(ip)) { 31 | throw new SecurityException("Connecting from IP address " + ip + " is not allowed"); 32 | } 33 | } else { 34 | throw new SecurityException("Invalid remote address " + remoteAddress); 35 | } 36 | 37 | super.addConnection(context, info); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/IPAuthenticationBroker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6; 2 | 3 | import java.util.List; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | import org.apache.activemq.broker.Broker; 8 | import org.apache.activemq.broker.BrokerFilter; 9 | import org.apache.activemq.broker.ConnectionContext; 10 | import org.apache.activemq.command.ConnectionInfo; 11 | 12 | public class IPAuthenticationBroker extends BrokerFilter { 13 | 14 | List allowedIPAddresses; 15 | Pattern pattern = Pattern.compile("^/([0-9\\.]*):(.*)"); 16 | 17 | public IPAuthenticationBroker(Broker next, List allowedIPAddresses) { 18 | super(next); 19 | this.allowedIPAddresses = allowedIPAddresses; 20 | } 21 | 22 | public void addConnection(ConnectionContext context, 23 | ConnectionInfo info) throws Exception { 24 | 25 | String remoteAddress = context.getConnection().getRemoteAddress(); 26 | 27 | Matcher matcher = pattern.matcher(remoteAddress); 28 | if (matcher.matches()) { 29 | String ip = matcher.group(1); 30 | if (!allowedIPAddresses.contains(ip)) { 31 | throw new SecurityException("Connecting from IP address " + ip + " is not allowed"); 32 | } 33 | } else { 34 | throw new SecurityException("Invalid remote address " + remoteAddress); 35 | } 36 | 37 | super.addConnection(context, info); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /examples/src/test/java/org/apache/activemq/book/ch11/CamelConfigTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.activemq.book.ch11; 18 | import org.apache.activemq.book.BrokerConfigTest; 19 | /** 20 | * A CamelConfigTest 21 | * 22 | */ 23 | public class CamelConfigTest extends BrokerConfigTest{ 24 | 25 | /** 26 | * @return 27 | * @see org.apache.activemq.book.BrokerConfigTest#getBrokerConfig() 28 | */ 29 | @Override 30 | protected String getBrokerConfig() { 31 | 32 | return "org/apache/activemq/book/ch11/broker.xml"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/src/test/java/org/apache/activemq/book/ch10/ScalingBrokerConfigTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.activemq.book.ch10; 18 | 19 | import org.apache.activemq.book.BrokerConfigTest; 20 | 21 | /** 22 | * A ScalingBrokerConfigTest 23 | * 24 | */ 25 | public class ScalingBrokerConfigTest extends BrokerConfigTest { 26 | /** 27 | * @return 28 | * @see org.apache.activemq.book.BrokerConfigTest#getBrokerConfig() 29 | */ 30 | @Override 31 | protected String getBrokerConfig() { 32 | return "org/apache/activemq/book/ch10/scalingconfig.xml"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch7/spring-2.0.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/advisory/ConsumerAdvisoryListener.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.advisory; 2 | 3 | import javax.jms.Message; 4 | import javax.jms.MessageListener; 5 | 6 | import org.apache.activemq.command.ActiveMQMessage; 7 | import org.apache.activemq.command.CommandTypes; 8 | import org.apache.activemq.command.ConsumerId; 9 | import org.apache.activemq.command.ConsumerInfo; 10 | import org.apache.activemq.command.DataStructure; 11 | import org.apache.activemq.command.RemoveInfo; 12 | 13 | public class ConsumerAdvisoryListener implements MessageListener { 14 | 15 | public void onMessage(Message message) { 16 | ActiveMQMessage msg = (ActiveMQMessage) message; 17 | DataStructure ds = msg.getDataStructure(); 18 | if (ds != null) { 19 | switch (ds.getDataStructureType()) { 20 | case CommandTypes.CONSUMER_INFO: 21 | ConsumerInfo consumerInfo = (ConsumerInfo) ds; 22 | System.out.println("Consumer '" + consumerInfo.getConsumerId() 23 | + "' subscribed to '" + consumerInfo.getDestination() 24 | + "'"); 25 | break; 26 | case CommandTypes.REMOVE_INFO: 27 | RemoveInfo removeInfo = (RemoveInfo) ds; 28 | ConsumerId consumerId = ((ConsumerId) removeInfo.getObjectId()); 29 | System.out 30 | .println("Consumer '" + consumerId + "' unsubscribed"); 31 | break; 32 | default: 33 | System.out.println("Unkown data structure type"); 34 | } 35 | } else { 36 | System.out.println("No data structure provided"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/activemq-custom.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 128.0.0.1 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/spring-2.0.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/src/main/php/transactions_receive.php: -------------------------------------------------------------------------------- 1 | connect(); 9 | $con->setReadTimeout(1); 10 | 11 | // subscribe to the queue 12 | $con->subscribe("/queue/transactions", array('ack' => 'client','activemq.prefetchSize' => 1 )); 13 | 14 | // try to receive some messages 15 | $con->begin("tx3"); 16 | $messages = array(); 17 | for ($i = 1; $i < 3; $i++) { 18 | $msg = $con->readFrame(); 19 | array_push($messages, $msg); 20 | $con->ack($msg, "tx3"); 21 | } 22 | // of we abort transaction, we will "rollback" out acks 23 | $con->abort("tx3"); 24 | 25 | $con->begin("tx4"); 26 | // so we need to ack received messages again 27 | // before we can receive more (prefetch = 1) 28 | if (count($messages) != 0) { 29 | foreach($messages as $msg) { 30 | $con->ack($msg, "tx4"); 31 | } 32 | } 33 | // now receive more messages 34 | for ($i = 1; $i < 3; $i++) { 35 | $msg = $con->readFrame(); 36 | $con->ack($msg, "tx4"); 37 | array_push($messages, $msg); 38 | } 39 | // commit all acks 40 | $con->commit("tx4"); 41 | 42 | 43 | echo "Processed messages {\n"; 44 | foreach($messages as $msg) { 45 | echo "\t$msg->body\n"; 46 | } 47 | echo "}\n"; 48 | 49 | //ensure there are no more messages in the queue 50 | $frame = $con->readFrame(); 51 | 52 | if ($frame === false) { 53 | echo "No more messages in the queue\n"; 54 | } else { 55 | echo "Warning: some messages still in the queue: $frame\n"; 56 | } 57 | 58 | // disconnect 59 | $con->disconnect(); -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jms-webapp-global 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.springframework.ide.eclipse.core.springbuilder 30 | 31 | 32 | 33 | 34 | org.maven.ide.eclipse.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.ide.eclipse.core.springnature 41 | org.eclipse.jem.workbench.JavaEMFNature 42 | org.eclipse.wst.common.modulecore.ModuleCoreNature 43 | org.eclipse.jdt.core.javanature 44 | org.maven.ide.eclipse.maven2Nature 45 | org.eclipse.wst.common.project.facet.core.nature 46 | org.eclipse.wst.jsdt.core.jsNature 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jms-webapp-jboss 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.springframework.ide.eclipse.core.springbuilder 30 | 31 | 32 | 33 | 34 | org.maven.ide.eclipse.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.ide.eclipse.core.springnature 41 | org.eclipse.jem.workbench.JavaEMFNature 42 | org.eclipse.wst.common.modulecore.ModuleCoreNature 43 | org.eclipse.jdt.core.javanature 44 | org.maven.ide.eclipse.maven2Nature 45 | org.eclipse.wst.common.project.facet.core.nature 46 | org.eclipse.wst.jsdt.core.jsNature 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jms-webapp-local 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.springframework.ide.eclipse.core.springbuilder 30 | 31 | 32 | 33 | 34 | org.maven.ide.eclipse.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.ide.eclipse.core.springnature 41 | org.eclipse.jem.workbench.JavaEMFNature 42 | org.eclipse.wst.common.modulecore.ModuleCoreNature 43 | org.eclipse.jdt.core.javanature 44 | org.maven.ide.eclipse.maven2Nature 45 | org.eclipse.wst.common.project.facet.core.nature 46 | org.eclipse.wst.jsdt.core.jsNature 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/portfolio/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch2.portfolio; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | 12 | public class Consumer { 13 | 14 | private static String brokerURL = "tcp://localhost:61616"; 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | public Consumer() throws JMSException { 20 | factory = new ActiveMQConnectionFactory(brokerURL); 21 | connection = factory.createConnection(); 22 | connection.start(); 23 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 24 | } 25 | 26 | public void close() throws JMSException { 27 | if (connection != null) { 28 | connection.close(); 29 | } 30 | } 31 | 32 | public static void main(String[] args) throws JMSException { 33 | Consumer consumer = new Consumer(); 34 | for (String stock : args) { 35 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 36 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 37 | messageConsumer.setMessageListener(new Listener()); 38 | } 39 | } 40 | 41 | public Session getSession() { 42 | return session; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/portfolio/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch3.portfolio; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | 12 | public class Consumer { 13 | 14 | private static String brokerURL = "tcp://localhost:61616"; 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | public Consumer() throws JMSException { 20 | factory = new ActiveMQConnectionFactory(brokerURL); 21 | connection = factory.createConnection(); 22 | connection.start(); 23 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 24 | } 25 | 26 | public void close() throws JMSException { 27 | if (connection != null) { 28 | connection.close(); 29 | } 30 | } 31 | 32 | public static void main(String[] args) throws JMSException { 33 | Consumer consumer = new Consumer(); 34 | for (String stock : args) { 35 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 36 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 37 | messageConsumer.setMessageListener(new Listener()); 38 | } 39 | } 40 | 41 | public Session getSession() { 42 | return session; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jms-webapp-geronimo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.springframework.ide.eclipse.core.springbuilder 30 | 31 | 32 | 33 | 34 | org.maven.ide.eclipse.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.ide.eclipse.core.springnature 41 | org.eclipse.jem.workbench.JavaEMFNature 42 | org.eclipse.wst.common.modulecore.ModuleCoreNature 43 | org.eclipse.jdt.core.javanature 44 | org.maven.ide.eclipse.maven2Nature 45 | org.eclipse.wst.common.project.facet.core.nature 46 | org.eclipse.wst.jsdt.core.jsNature 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/broker/Broker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.broker; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.apache.activemq.broker.BrokerPlugin; 7 | import org.apache.activemq.broker.BrokerService; 8 | import org.apache.activemq.security.AuthenticationUser; 9 | import org.apache.activemq.security.JaasAuthenticationPlugin; 10 | import org.apache.activemq.security.SimpleAuthenticationPlugin; 11 | 12 | public class Broker { 13 | 14 | public static void main(String[] args) throws Exception { 15 | BrokerService broker = new BrokerService(); 16 | broker.setBrokerName("localhost"); 17 | broker.setDataDirectory("data/"); 18 | 19 | SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(); 20 | 21 | List users = new ArrayList(); 22 | users.add(new AuthenticationUser("admin", "password", "admins,publishers,consumers")); 23 | users.add(new AuthenticationUser("publisher", "password", "publishers,consumers")); 24 | users.add(new AuthenticationUser("consumer", "password", "consumers")); 25 | users.add(new AuthenticationUser("guest", "password", "guests")); 26 | authentication.setUsers(users); 27 | 28 | broker.setPlugins(new BrokerPlugin[]{authentication}); 29 | 30 | /*JaasAuthenticationPlugin jaas = new JaasAuthenticationPlugin(); 31 | jaas.setConfiguration("src/main/resources/org/apache/activemq/book/ch5/login.config"); 32 | broker.setPlugins(new BrokerPlugin[]{jaas});*/ 33 | 34 | broker.addConnector("tcp://localhost:61616"); 35 | 36 | broker.start(); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/activemq-simple.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 25 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch2/jobs/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch2.jobs; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | 12 | public class Consumer { 13 | 14 | private static String brokerURL = "tcp://localhost:61616"; 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | private String jobs[] = new String[]{"suspend", "delete"}; 20 | 21 | public Consumer() throws JMSException { 22 | factory = new ActiveMQConnectionFactory(brokerURL); 23 | connection = factory.createConnection(); 24 | connection.start(); 25 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 26 | } 27 | 28 | public void close() throws JMSException { 29 | if (connection != null) { 30 | connection.close(); 31 | } 32 | } 33 | 34 | public static void main(String[] args) throws JMSException { 35 | Consumer consumer = new Consumer(); 36 | for (String job : consumer.jobs) { 37 | Destination destination = consumer.getSession().createQueue("JOBS." + job); 38 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 39 | messageConsumer.setMessageListener(new Listener(job)); 40 | } 41 | } 42 | 43 | public Session getSession() { 44 | return session; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/jobs/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch3.jobs; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | 12 | public class Consumer { 13 | 14 | private static String brokerURL = "tcp://localhost:61616"; 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | private String jobs[] = new String[]{"suspend", "delete"}; 20 | 21 | public Consumer() throws JMSException { 22 | factory = new ActiveMQConnectionFactory(brokerURL); 23 | connection = factory.createConnection(); 24 | connection.start(); 25 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 26 | } 27 | 28 | public void close() throws JMSException { 29 | if (connection != null) { 30 | connection.close(); 31 | } 32 | } 33 | 34 | public static void main(String[] args) throws JMSException { 35 | Consumer consumer = new Consumer(); 36 | for (String job : consumer.jobs) { 37 | Destination destination = consumer.getSession().createQueue("JOBS." + job); 38 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 39 | messageConsumer.setMessageListener(new Listener(job)); 40 | } 41 | } 42 | 43 | public Session getSession() { 44 | return session; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/jmx/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.jmx; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | 12 | public class Consumer { 13 | 14 | private static String brokerURL = "tcp://localhost:61616?jms.prefetchPolicy.all=1"; 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | private String jobs[] = new String[]{"suspend", "delete"}; 20 | 21 | public Consumer() throws JMSException { 22 | factory = new ActiveMQConnectionFactory(brokerURL); 23 | connection = factory.createConnection(); 24 | connection.start(); 25 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 26 | } 27 | 28 | public void close() throws JMSException { 29 | if (connection != null) { 30 | connection.close(); 31 | } 32 | } 33 | 34 | public static void main(String[] args) throws JMSException { 35 | Consumer consumer = new Consumer(); 36 | for (String job : consumer.jobs) { 37 | Destination destination = consumer.getSession().createQueue("JOBS." + job); 38 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 39 | messageConsumer.setMessageListener(new Listener(job)); 40 | } 41 | } 42 | 43 | public Session getSession() { 44 | return session; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /examples/src/main/assembly/activemq-in-action-src.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | src 4 | 5 | zip 6 | 7 | false 8 | 9 | 10 | ${project.basedir} 11 | activemq-in-action-examples-src 12 | 29 | 30 | **/*.graffle 31 | **/*.tiff 32 | **/*.jpeg 33 | **/*.jpg 34 | **/*.gif 35 | **/*.png 36 | **/*.jar 37 | **/target/** 38 | **/target*/** 39 | **/build/** 40 | **/eclipse-classes/** 41 | **/.* 42 | **/.*/** 43 | **/surefire* 44 | 45 | unix 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/xbean/Broker.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.xbean; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.apache.activemq.broker.BrokerPlugin; 7 | import org.apache.activemq.broker.BrokerService; 8 | import org.apache.activemq.security.AuthenticationUser; 9 | import org.apache.activemq.security.SimpleAuthenticationPlugin; 10 | 11 | public class Broker { 12 | 13 | public static void main(String[] args) throws Exception { 14 | BrokerService broker = new BrokerService(); 15 | broker.setBrokerName("myBroker"); 16 | broker.setDataDirectory("data/"); 17 | 18 | SimpleAuthenticationPlugin authentication = new SimpleAuthenticationPlugin(); 19 | 20 | List users = new ArrayList(); 21 | users.add(new AuthenticationUser("admin", "password", "admins,publishers,consumers")); 22 | users.add(new AuthenticationUser("publisher", "password", "publishers,consumers")); 23 | users.add(new AuthenticationUser("consumer", "password", "consumers")); 24 | users.add(new AuthenticationUser("guest", "password", "guests")); 25 | authentication.setUsers(users); 26 | 27 | broker.setPlugins(new BrokerPlugin[]{authentication}); 28 | 29 | /*JaasAuthenticationPlugin jaas = new JaasAuthenticationPlugin(); 30 | jaas.setConfiguration("src/main/resources/org/apache/activemq/book/ch5/login.config"); 31 | broker.setPlugins(new BrokerPlugin[]{jaas});*/ 32 | 33 | broker.addConnector("tcp://localhost:61616"); 34 | 35 | broker.start(); 36 | 37 | System.out.println(); 38 | System.out.println("Press any key to stop the broker"); 39 | System.out.println(); 40 | 41 | System.in.read(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/activemq-simple.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch8/jndi.properties: -------------------------------------------------------------------------------- 1 | # 2 | # This is an example jndi.properties file for use with ActiveMQ. To make use of 3 | # the locally available ActiveMQ JNDI provider place this file in the classpath 4 | # of the client application. 5 | # 6 | 7 | # 8 | # The java.naming.factory.initial property is a standard JNDI system property 9 | # (http://java.sun.com/products/jndi/tutorial/beyond/env/context.html) 10 | # that is used to specify the InitialContextFactory implementation to use. In 11 | # this instance, the ActiveMQInitialContextFactory is used to provide a locally 12 | # available context factory. 13 | # 14 | java.naming.factory.initial = \ 15 | org.apache.activemq.jndi.ActiveMQInitialContextFactory 16 | 17 | # 18 | # The JNDI names for the connection factories to be registered in JNDI. These 19 | # are the name that should be used to lookup the connection factories in JNDI. 20 | # 21 | connectionFactoryNames = remotePublisherConnectionFactory, \ 22 | remoteConsumerConnectionFactory 23 | 24 | # 25 | # Configure the connection factory for publishers 26 | # 27 | connection.remotePublisherConnectionFactory.brokerURL = tcp://hostA:61616 28 | connection.remotePublisherConnectionFactory.username = publisher 29 | connection.remotePublisherConnectionFactory.username = password 30 | 31 | # 32 | # Configure the connection factory for consumers 33 | # 34 | connection.remoteConsumerConnectionFactory.username = tcp://hostA:61616 35 | connection.remoteConsumerConnectionFactory.username = consumer 36 | connection.remoteConsumerConnectionFactory.username = password 37 | 38 | # 39 | # Define some destinations to be registered in JNDI. 40 | # 41 | queue.TEST.FOO = TEST.FOO 42 | topic.TEST.VAR = TEST.BAR -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/java/org/apache/activemq/book/ch8/jms/service/JmsMessageSenderService.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.service; 2 | 3 | import javax.jms.JMSException; 4 | import javax.jms.Message; 5 | import javax.jms.Session; 6 | import javax.jms.TextMessage; 7 | 8 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 9 | import org.apache.activemq.command.ActiveMQQueue; 10 | import org.springframework.jms.core.JmsTemplate; 11 | import org.springframework.jms.core.MessageCreator; 12 | 13 | /** 14 | * @author bsnyder 15 | * 16 | */ 17 | public class JmsMessageSenderService { 18 | 19 | private JmsTemplate jmsTemplate; 20 | 21 | public void sendMessage(final JmsMessage bean) throws JMSException { 22 | 23 | if (bean.isPersistent()) { 24 | jmsTemplate.setDeliveryPersistent(bean.isPersistent()); 25 | } 26 | 27 | if (0 != bean.getTimeToLive()) { 28 | jmsTemplate.setTimeToLive(bean.getTimeToLive()); 29 | } 30 | 31 | jmsTemplate.send(new MessageCreator() { 32 | public Message createMessage(Session session) throws JMSException { 33 | 34 | TextMessage message = session.createTextMessage(bean 35 | .getMessagePayload()); 36 | 37 | if (bean.getReplyTo() != null && !bean.getReplyTo().equals("")) { 38 | ActiveMQQueue replyToQueue = new ActiveMQQueue(bean.getReplyTo()); 39 | message.setJMSReplyTo(replyToQueue); 40 | } 41 | return message; 42 | } 43 | }); 44 | } 45 | 46 | public void setJmsTemplate(JmsTemplate jmsTemplate) { 47 | this.jmsTemplate = jmsTemplate; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/java/org/apache/activemq/book/ch8/jms/service/JmsMessageSenderService.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.service; 2 | 3 | import javax.jms.JMSException; 4 | import javax.jms.Message; 5 | import javax.jms.Session; 6 | import javax.jms.TextMessage; 7 | 8 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 9 | import org.apache.activemq.command.ActiveMQQueue; 10 | import org.springframework.jms.core.JmsTemplate; 11 | import org.springframework.jms.core.MessageCreator; 12 | 13 | /** 14 | * @author bsnyder 15 | * 16 | */ 17 | public class JmsMessageSenderService { 18 | 19 | private JmsTemplate jmsTemplate; 20 | 21 | public void sendMessage(final JmsMessage bean) throws JMSException { 22 | 23 | if (bean.isPersistent()) { 24 | jmsTemplate.setDeliveryPersistent(bean.isPersistent()); 25 | } 26 | 27 | if (0 != bean.getTimeToLive()) { 28 | jmsTemplate.setTimeToLive(bean.getTimeToLive()); 29 | } 30 | 31 | jmsTemplate.send(new MessageCreator() { 32 | public Message createMessage(Session session) throws JMSException { 33 | TextMessage message = session.createTextMessage(bean.getMessagePayload()); 34 | 35 | if (bean.getReplyTo() != null && !bean.getReplyTo().equals("")) { 36 | ActiveMQQueue replyToQueue = new ActiveMQQueue(bean.getReplyTo()); 37 | message.setJMSReplyTo(replyToQueue); 38 | } 39 | 40 | return message; 41 | } 42 | }); 43 | } 44 | 45 | public void setJmsTemplate(JmsTemplate jmsTemplate) { 46 | this.jmsTemplate = jmsTemplate; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/java/org/apache/activemq/book/ch8/jms/service/JmsMessageSenderService.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.service; 2 | 3 | import javax.jms.JMSException; 4 | import javax.jms.Message; 5 | import javax.jms.Session; 6 | import javax.jms.TextMessage; 7 | 8 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 9 | import org.apache.activemq.command.ActiveMQQueue; 10 | import org.springframework.jms.core.JmsTemplate; 11 | import org.springframework.jms.core.MessageCreator; 12 | 13 | /** 14 | * @author bsnyder 15 | * 16 | */ 17 | public class JmsMessageSenderService { 18 | 19 | private JmsTemplate jmsTemplate; 20 | 21 | public void sendMessage(final JmsMessage bean) throws JMSException { 22 | 23 | if (bean.isPersistent()) { 24 | jmsTemplate.setDeliveryPersistent(bean.isPersistent()); 25 | } 26 | 27 | if (0 != bean.getTimeToLive()) { 28 | jmsTemplate.setTimeToLive(bean.getTimeToLive()); 29 | } 30 | 31 | jmsTemplate.send(new MessageCreator() { 32 | public Message createMessage(Session session) throws JMSException { 33 | TextMessage message = session.createTextMessage(bean.getMessagePayload()); 34 | 35 | if (bean.getReplyTo() != null && !bean.getReplyTo().equals("")) { 36 | ActiveMQQueue replyToQueue = new ActiveMQQueue(bean.getReplyTo()); 37 | message.setJMSReplyTo(replyToQueue); 38 | } 39 | 40 | return message; 41 | } 42 | }); 43 | } 44 | 45 | public void setJmsTemplate(JmsTemplate jmsTemplate) { 46 | this.jmsTemplate = jmsTemplate; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch5/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch5; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | import org.apache.activemq.book.ch2.portfolio.Listener; 12 | 13 | public class Consumer { 14 | 15 | private static String brokerURL = "tcp://localhost:61616"; 16 | private static transient ConnectionFactory factory; 17 | private transient Connection connection; 18 | private transient Session session; 19 | 20 | private String username = "guest"; 21 | private String password = "password"; 22 | 23 | public Consumer() throws JMSException { 24 | factory = new ActiveMQConnectionFactory(brokerURL); 25 | connection = factory.createConnection(username, password); 26 | connection.start(); 27 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 28 | } 29 | 30 | public void close() throws JMSException { 31 | if (connection != null) { 32 | connection.close(); 33 | } 34 | } 35 | 36 | public static void main(String[] args) throws JMSException { 37 | Consumer consumer = new Consumer(); 38 | for (String stock : args) { 39 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 40 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 41 | messageConsumer.setMessageListener(new Listener()); 42 | } 43 | } 44 | 45 | public Session getSession() { 46 | return session; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/java/org/apache/activemq/book/ch8/jms/service/JmsMessageSenderService.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.service; 2 | 3 | import javax.jms.JMSException; 4 | import javax.jms.Message; 5 | import javax.jms.Session; 6 | import javax.jms.TextMessage; 7 | 8 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 9 | import org.apache.activemq.command.ActiveMQQueue; 10 | import org.springframework.jms.core.JmsTemplate; 11 | import org.springframework.jms.core.MessageCreator; 12 | 13 | /** 14 | * @author bsnyder 15 | * 16 | */ 17 | public class JmsMessageSenderService { 18 | 19 | private JmsTemplate jmsTemplate; 20 | 21 | public void sendMessage(final JmsMessage bean) throws JMSException { 22 | 23 | if (bean.isPersistent()) { 24 | jmsTemplate.setDeliveryPersistent(bean.isPersistent()); 25 | } 26 | 27 | if (0 != bean.getTimeToLive()) { 28 | jmsTemplate.setTimeToLive(bean.getTimeToLive()); 29 | } 30 | 31 | jmsTemplate.send(new MessageCreator() { 32 | public Message createMessage(Session session) throws JMSException { 33 | TextMessage message = session.createTextMessage(bean.getMessagePayload()); 34 | 35 | if (bean.getReplyTo() != null && !bean.getReplyTo().equals("")) { 36 | ActiveMQQueue replyToQueue = new ActiveMQQueue(bean.getReplyTo()); 37 | message.setJMSReplyTo(replyToQueue); 38 | } 39 | 40 | return message; 41 | } 42 | }); 43 | } 44 | 45 | public void setJmsTemplate(JmsTemplate jmsTemplate) { 46 | this.jmsTemplate = jmsTemplate; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/WEB-INF/jsp/send.jsp: -------------------------------------------------------------------------------- 1 | <%@ include file="/WEB-INF/jsp/include.jsp" %> 2 | 3 | 4 | 5 | JMS Message Sender 6 | 18 | 19 | 20 | 21 |

Send a JMS Message

22 | 23 | 24 | 25 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | 43 | 46 | 47 | 48 | 51 | 54 | 55 | 56 | 59 | 62 | 63 | 64 | 67 | 68 |
  26 | 27 |
${successfulSend}
28 |
29 |
33 | Reply To: 34 | 36 | 37 |
41 | Time To Live: 42 | 44 | 45 |
49 | Persistent: 50 | 52 | 53 |
57 | Message: 58 | 60 | 61 |
65 | 66 |
69 |
70 | 71 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/jsp/send.jsp: -------------------------------------------------------------------------------- 1 | <%@ include file="/WEB-INF/jsp/include.jsp" %> 2 | 3 | 4 | 5 | JMS Message Sender 6 | 18 | 19 | 20 | 21 |

Send a JMS Message

22 | 23 | 24 | 25 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | 43 | 46 | 47 | 48 | 51 | 54 | 55 | 56 | 59 | 62 | 63 | 64 | 67 | 68 |
  26 | 27 |
${successfulSend}
28 |
29 |
33 | Reply To: 34 | 36 | 37 |
41 | Time To Live: 42 | 44 | 45 |
49 | Persistent: 50 | 52 | 53 |
57 | Message: 58 | 60 | 61 |
65 | 66 |
69 |
70 | 71 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/WEB-INF/jsp/send.jsp: -------------------------------------------------------------------------------- 1 | <%@ include file="/WEB-INF/jsp/include.jsp" %> 2 | 3 | 4 | 5 | JMS Message Sender 6 | 18 | 19 | 20 | 21 |

Send a JMS Message

22 | 23 | 24 | 25 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | 43 | 46 | 47 | 48 | 51 | 54 | 55 | 56 | 59 | 62 | 63 | 64 | 67 | 68 |
  26 | 27 |
${successfulSend}
28 |
29 |
33 | Reply To: 34 | 36 | 37 |
41 | Time To Live: 42 | 44 | 45 |
49 | Persistent: 50 | 52 | 53 |
57 | Message: 58 | 60 | 61 |
65 | 66 |
69 |
70 | 71 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/WEB-INF/jsp/send.jsp: -------------------------------------------------------------------------------- 1 | <%@ include file="/WEB-INF/jsp/include.jsp" %> 2 | 3 | 4 | 5 | JMS Message Sender 6 | 18 | 19 | 20 | 21 |

Send a JMS Message

22 | 23 | 24 | 25 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | 43 | 46 | 47 | 48 | 51 | 54 | 55 | 56 | 59 | 62 | 63 | 64 | 67 | 68 |
  26 | 27 |
${successfulSend}
28 |
29 |
33 | Reply To: 34 | 36 | 37 |
41 | Time To Live: 42 | 44 | 45 |
49 | Persistent: 50 | 52 | 53 |
57 | Message: 58 | 60 | 61 |
65 | 66 |
69 |
70 | 71 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/spring/StockMessageCreator.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.spring; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Map; 5 | 6 | import javax.jms.Destination; 7 | import javax.jms.JMSException; 8 | import javax.jms.MapMessage; 9 | import javax.jms.Message; 10 | import javax.jms.Session; 11 | 12 | import org.apache.activemq.command.ActiveMQMapMessage; 13 | import org.springframework.jms.core.MessageCreator; 14 | 15 | public class StockMessageCreator implements MessageCreator { 16 | 17 | private int MAX_DELTA_PERCENT = 1; 18 | private Map LAST_PRICES = new Hashtable(); 19 | 20 | Destination stock; 21 | 22 | public StockMessageCreator(Destination stock) { 23 | this.stock = stock; 24 | } 25 | 26 | public Message createMessage(Session session) throws JMSException { 27 | Double value = LAST_PRICES.get(stock); 28 | if (value == null) { 29 | value = new Double(Math.random() * 100); 30 | } 31 | 32 | // lets mutate the value by some percentage 33 | double oldPrice = value.doubleValue(); 34 | value = new Double(mutatePrice(oldPrice)); 35 | LAST_PRICES.put(stock, value); 36 | double price = value.doubleValue(); 37 | 38 | double offer = price * 1.001; 39 | 40 | boolean up = (price > oldPrice); 41 | MapMessage message = session.createMapMessage(); 42 | message.setString("stock", stock.toString()); 43 | message.setDouble("price", price); 44 | message.setDouble("offer", offer); 45 | message.setBoolean("up", up); 46 | System.out.println("Sending: " + ((ActiveMQMapMessage)message).getContentMap() + " on destination: " + stock); 47 | return message; 48 | } 49 | 50 | protected double mutatePrice(double price) { 51 | double percentChange = (2 * Math.random() * MAX_DELTA_PERCENT) 52 | - MAX_DELTA_PERCENT; 53 | 54 | return price * (100 + percentChange) / 100; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/spring/StockMessageCreator.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.spring; 2 | 3 | import java.util.Hashtable; 4 | import java.util.Map; 5 | 6 | import javax.jms.Destination; 7 | import javax.jms.JMSException; 8 | import javax.jms.MapMessage; 9 | import javax.jms.Message; 10 | import javax.jms.Session; 11 | 12 | import org.apache.activemq.command.ActiveMQMapMessage; 13 | import org.springframework.jms.core.MessageCreator; 14 | 15 | public class StockMessageCreator implements MessageCreator { 16 | 17 | private int MAX_DELTA_PERCENT = 1; 18 | private Map LAST_PRICES = new Hashtable(); 19 | 20 | Destination stock; 21 | 22 | public StockMessageCreator(Destination stock) { 23 | this.stock = stock; 24 | } 25 | 26 | public Message createMessage(Session session) throws JMSException { 27 | Double value = LAST_PRICES.get(stock); 28 | if (value == null) { 29 | value = new Double(Math.random() * 100); 30 | } 31 | 32 | // lets mutate the value by some percentage 33 | double oldPrice = value.doubleValue(); 34 | value = new Double(mutatePrice(oldPrice)); 35 | LAST_PRICES.put(stock, value); 36 | double price = value.doubleValue(); 37 | 38 | double offer = price * 1.001; 39 | 40 | boolean up = (price > oldPrice); 41 | MapMessage message = session.createMapMessage(); 42 | message.setString("stock", stock.toString()); 43 | message.setDouble("price", price); 44 | message.setDouble("offer", offer); 45 | message.setBoolean("up", up); 46 | System.out.println("Sending: " + ((ActiveMQMapMessage)message).getContentMap() + " on destination: " + stock); 47 | return message; 48 | } 49 | 50 | protected double mutatePrice(double price) { 51 | double percentChange = (2 * Math.random() * MAX_DELTA_PERCENT) 52 | - MAX_DELTA_PERCENT; 53 | 54 | return price * (100 + percentChange) / 100; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | import org.apache.activemq.book.ch3.portfolio.Listener; 12 | 13 | public class Consumer { 14 | 15 | private static String brokerURL = "tcp://localhost:61616"; 16 | private static transient ConnectionFactory factory; 17 | private transient Connection connection; 18 | private transient Session session; 19 | 20 | private String username = "guest"; 21 | private String password = "password"; 22 | 23 | public Consumer() throws JMSException { 24 | factory = new ActiveMQConnectionFactory(brokerURL); 25 | connection = factory.createConnection(username, password); 26 | connection.start(); 27 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 28 | } 29 | 30 | public void close() throws JMSException { 31 | if (connection != null) { 32 | connection.close(); 33 | } 34 | } 35 | 36 | public static void main(String[] args) throws Exception { 37 | Consumer consumer = new Consumer(); 38 | try { 39 | for (String stock : args) { 40 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 41 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 42 | messageConsumer.setMessageListener(new Listener()); 43 | } 44 | System.out.println("Press any key to exit"); 45 | System.in.read(); 46 | } finally { 47 | consumer.close(); 48 | } 49 | } 50 | 51 | public Session getSession() { 52 | return session; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch10/scalingconfig.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch3/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch3; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | import org.apache.activemq.book.ch2.portfolio.Listener; 12 | 13 | public class Consumer { 14 | 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | public Consumer(String brokerURL) throws JMSException { 20 | factory = new ActiveMQConnectionFactory(brokerURL); 21 | connection = factory.createConnection(); 22 | connection.start(); 23 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 24 | } 25 | 26 | public void close() throws JMSException { 27 | if (connection != null) { 28 | connection.close(); 29 | } 30 | } 31 | 32 | public static void main(String[] args) throws JMSException { 33 | if (args.length == 0) { 34 | System.err.println("Please define connection URI!"); 35 | return; 36 | } 37 | 38 | //define connection URI 39 | Consumer consumer = new Consumer(args[0]); 40 | 41 | //extract topics from the rest of arguments 42 | String[] topics = new String[args.length - 1]; 43 | System.arraycopy(args, 1, topics, 0, args.length - 1); 44 | for (String stock : topics) { 45 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 46 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 47 | messageConsumer.setMessageListener(new Listener()); 48 | } 49 | } 50 | 51 | public Session getSession() { 52 | return session; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch4/Consumer.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch4; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.JMSException; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.Session; 9 | 10 | import org.apache.activemq.ActiveMQConnectionFactory; 11 | import org.apache.activemq.book.ch3.portfolio.Listener; 12 | 13 | public class Consumer { 14 | 15 | private static transient ConnectionFactory factory; 16 | private transient Connection connection; 17 | private transient Session session; 18 | 19 | public Consumer(String brokerURL) throws JMSException { 20 | factory = new ActiveMQConnectionFactory(brokerURL); 21 | connection = factory.createConnection(); 22 | connection.start(); 23 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 24 | } 25 | 26 | public void close() throws JMSException { 27 | if (connection != null) { 28 | connection.close(); 29 | } 30 | } 31 | 32 | public static void main(String[] args) throws JMSException { 33 | if (args.length == 0) { 34 | System.err.println("Please define connection URI!"); 35 | return; 36 | } 37 | 38 | //define connection URI 39 | Consumer consumer = new Consumer(args[0]); 40 | 41 | //extract topics from the rest of arguments 42 | String[] topics = new String[args.length - 1]; 43 | System.arraycopy(args, 1, topics, 0, args.length - 1); 44 | for (String stock : topics) { 45 | Destination destination = consumer.getSession().createTopic("STOCKS." + stock); 46 | MessageConsumer messageConsumer = consumer.getSession().createConsumer(destination); 47 | messageConsumer.setMessageListener(new Listener()); 48 | } 49 | } 50 | 51 | public Session getSession() { 52 | return session; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch11/camel.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | org.foo.bar 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/java/org/apache/activemq/book/ch8/jms/web/controller/JmsMessageSenderController.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.web.controller; 2 | 3 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 4 | import org.apache.activemq.book.ch8.jms.service.JmsMessageSenderService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.support.SessionStatus; 13 | 14 | 15 | /** 16 | * @author bsnyder 17 | * 18 | */ 19 | @Controller 20 | @RequestMapping("/send.html") 21 | public class JmsMessageSenderController { 22 | 23 | @Autowired 24 | private JmsMessageSenderService messageSenderService; 25 | 26 | @RequestMapping(method = RequestMethod.GET) 27 | public String setupForm(ModelMap model) { 28 | model.addAttribute("jmsMessageBean", new JmsMessage()); 29 | model.remove("successfulSend"); 30 | 31 | return "send"; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.POST) 35 | public String onSubmit( 36 | @ModelAttribute("jmsMessageBean") JmsMessage jmsMessageBean, 37 | BindingResult result, 38 | SessionStatus status, 39 | ModelMap model) 40 | throws Exception { 41 | messageSenderService.sendMessage(jmsMessageBean); 42 | model.addAttribute("successfulSend", "The message was sent successfully"); 43 | model.addAttribute("jmsMessageBean", new JmsMessage()); 44 | status.setComplete(); 45 | 46 | return "send"; 47 | } 48 | 49 | public void setMessageSender(JmsMessageSenderService messageSender) { 50 | this.messageSenderService = messageSender; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/java/org/apache/activemq/book/ch8/jms/web/controller/JmsMessageSenderController.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.web.controller; 2 | 3 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 4 | import org.apache.activemq.book.ch8.jms.service.JmsMessageSenderService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.support.SessionStatus; 13 | 14 | 15 | /** 16 | * @author bsnyder 17 | * 18 | */ 19 | @Controller 20 | @RequestMapping("/send.html") 21 | public class JmsMessageSenderController { 22 | 23 | @Autowired 24 | private JmsMessageSenderService messageSenderService; 25 | 26 | @RequestMapping(method = RequestMethod.GET) 27 | public String setupForm(ModelMap model) { 28 | model.addAttribute("jmsMessageBean", new JmsMessage()); 29 | model.remove("successfulSend"); 30 | 31 | return "send"; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.POST) 35 | public String onSubmit( 36 | @ModelAttribute("jmsMessageBean") JmsMessage jmsMessageBean, 37 | BindingResult result, 38 | SessionStatus status, 39 | ModelMap model) 40 | throws Exception { 41 | messageSenderService.sendMessage(jmsMessageBean); 42 | model.addAttribute("successfulSend", "The message was sent successfully"); 43 | model.addAttribute("jmsMessageBean", new JmsMessage()); 44 | status.setComplete(); 45 | 46 | return "send"; 47 | } 48 | 49 | public void setMessageSender(JmsMessageSenderService messageSender) { 50 | this.messageSenderService = messageSender; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/java/org/apache/activemq/book/ch8/jms/web/controller/JmsMessageSenderController.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.web.controller; 2 | 3 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 4 | import org.apache.activemq.book.ch8.jms.service.JmsMessageSenderService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.support.SessionStatus; 13 | 14 | 15 | /** 16 | * @author bsnyder 17 | * 18 | */ 19 | @Controller 20 | @RequestMapping("/send.html") 21 | public class JmsMessageSenderController { 22 | 23 | @Autowired 24 | private JmsMessageSenderService messageSenderService; 25 | 26 | @RequestMapping(method = RequestMethod.GET) 27 | public String setupForm(ModelMap model) { 28 | model.addAttribute("jmsMessageBean", new JmsMessage()); 29 | model.remove("successfulSend"); 30 | 31 | return "send"; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.POST) 35 | public String onSubmit( 36 | @ModelAttribute("jmsMessageBean") JmsMessage jmsMessageBean, 37 | BindingResult result, 38 | SessionStatus status, 39 | ModelMap model) 40 | throws Exception { 41 | messageSenderService.sendMessage(jmsMessageBean); 42 | model.addAttribute("successfulSend", "The message was sent successfully"); 43 | model.addAttribute("jmsMessageBean", new JmsMessage()); 44 | status.setComplete(); 45 | 46 | return "send"; 47 | } 48 | 49 | public void setMessageSender(JmsMessageSenderService messageSender) { 50 | this.messageSenderService = messageSender; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/java/org/apache/activemq/book/ch8/jms/web/controller/JmsMessageSenderController.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch8.jms.web.controller; 2 | 3 | import org.apache.activemq.book.ch8.jms.domain.JmsMessage; 4 | import org.apache.activemq.book.ch8.jms.service.JmsMessageSenderService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.ModelMap; 8 | import org.springframework.validation.BindingResult; 9 | import org.springframework.web.bind.annotation.ModelAttribute; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.support.SessionStatus; 13 | 14 | 15 | /** 16 | * @author bsnyder 17 | * 18 | */ 19 | @Controller 20 | @RequestMapping("/send.html") 21 | public class JmsMessageSenderController { 22 | 23 | @Autowired 24 | private JmsMessageSenderService messageSenderService; 25 | 26 | @RequestMapping(method = RequestMethod.GET) 27 | public String setupForm(ModelMap model) { 28 | model.addAttribute("jmsMessageBean", new JmsMessage()); 29 | model.remove("successfulSend"); 30 | 31 | return "send"; 32 | } 33 | 34 | @RequestMapping(method = RequestMethod.POST) 35 | public String onSubmit( 36 | @ModelAttribute("jmsMessageBean") JmsMessage jmsMessageBean, 37 | BindingResult result, 38 | SessionStatus status, 39 | ModelMap model) 40 | throws Exception { 41 | messageSenderService.sendMessage(jmsMessageBean); 42 | model.addAttribute("successfulSend", "The message was sent successfully"); 43 | model.addAttribute("jmsMessageBean", new JmsMessage()); 44 | status.setComplete(); 45 | 46 | return "send"; 47 | } 48 | 49 | public void setMessageSender(JmsMessageSenderService messageSender) { 50 | this.messageSenderService = messageSender; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch4/KahaDBEmbeddedBroker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.activemq.book.ch4; 18 | 19 | import java.io.File; 20 | import org.apache.activemq.broker.BrokerService; 21 | import org.apache.activemq.store.kahadb.KahaDBStore; 22 | 23 | public class KahaDBEmbeddedBroker { 24 | 25 | public void createEmbeddedBroker() throws Exception { 26 | 27 | BrokerService broker = new BrokerService(); 28 | File dataFileDir = new File("target/amq-in-action/kahadb"); 29 | 30 | KahaDBStore kaha = new KahaDBStore(); 31 | kaha.setDirectory(dataFileDir); 32 | 33 | // Using a bigger journal file 34 | kaha.setJournalMaxFileLength(1024*1204*100); 35 | 36 | // small batch means more frequent and smaller writes 37 | kaha.setIndexWriteBatchSize(100); 38 | // do the index write in a separate thread 39 | kaha.setEnableIndexWriteAsync(true); 40 | 41 | broker.setPersistenceAdapter(kaha); 42 | //create a transport connector 43 | broker.addConnector("tcp://localhost:61616"); 44 | //start the broker 45 | broker.start(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch11/RetroactiveConsumer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.activemq.book.ch11; 18 | 19 | import org.apache.activemq.ActiveMQConnectionFactory; 20 | import javax.jms.Connection; 21 | import javax.jms.ConnectionFactory; 22 | import javax.jms.JMSException; 23 | import javax.jms.Message; 24 | import javax.jms.MessageConsumer; 25 | import javax.jms.Session; 26 | import javax.jms.Topic; 27 | 28 | /** 29 | * A RetroactiveConsumer 30 | * 31 | */ 32 | public class RetroactiveConsumer { 33 | public void createARetoractiveConsumer() throws JMSException { 34 | String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL; 35 | ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerURI); 36 | Connection connection = connectionFactory.createConnection(); 37 | connection.start(); 38 | Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 39 | Topic topic = session.createTopic("soccer.division1.leeds?consumer.retroactive=true"); 40 | MessageConsumer consumer = session.createConsumer(topic); 41 | Message result = consumer.receive(); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/src/main/php/durable.php: -------------------------------------------------------------------------------- 1 | setReadTimeout(1); 11 | // set clientId on a consumer to make it durable 12 | $consumer->clientId = "test"; 13 | // connect 14 | $producer->connect(); 15 | $consumer->connect(); 16 | // subscribe to the topic 17 | $consumer->subscribe("/topic/test"); 18 | 19 | sleep(1); 20 | 21 | // send a message to the topic 22 | $producer->send("/topic/test", "test", array('persistent'=>'true')); 23 | echo "Message 'test' sent to topic\n"; 24 | 25 | // receive a message from the topic 26 | $msg = $consumer->readFrame(); 27 | 28 | // do what you want with the message 29 | if ( $msg != null) { 30 | echo "Message '$msg->body' received from topic\n"; 31 | $consumer->ack($msg); 32 | } else { 33 | echo "Failed to receive a message\n"; 34 | } 35 | 36 | sleep(1); 37 | 38 | // disconnect durable consumer 39 | $consumer->unsubscribe("/topic/test"); 40 | $consumer->disconnect(); 41 | echo "Disconnecting consumer\n"; 42 | 43 | // send a message while consumer is disconnected 44 | // note: only persistent messages will be redelivered to the durable consumer 45 | $producer->send("/topic/test", "test1", array('persistent'=>'true')); 46 | echo "Message 'test1' sent to topic\n"; 47 | 48 | 49 | // reconnect the durable consumer 50 | $consumer = new Stomp("tcp://localhost:61613"); 51 | $consumer->clientId = "test"; 52 | $consumer->connect(); 53 | $consumer->subscribe("/topic/test"); 54 | echo "Reconnecting consumer\n"; 55 | 56 | // receive a message from the topic 57 | $msg = $consumer->readFrame(); 58 | 59 | // do what you want with the message 60 | if ( $msg != null) { 61 | echo "Message '$msg->body' received from topic\n"; 62 | $consumer->ack($msg); 63 | } else { 64 | echo "Failed to receive a message\n"; 65 | } 66 | 67 | // disconnect 68 | $consumer->unsubscribe("/topic/test"); 69 | $consumer->disconnect(); 70 | $producer->disconnect(); 71 | 72 | ?> -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/jmx/Stats.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.jmx; 2 | 3 | import javax.management.MBeanServerConnection; 4 | import javax.management.MBeanServerInvocationHandler; 5 | import javax.management.ObjectName; 6 | import javax.management.remote.JMXConnector; 7 | import javax.management.remote.JMXConnectorFactory; 8 | import javax.management.remote.JMXServiceURL; 9 | 10 | import org.apache.activemq.broker.jmx.BrokerViewMBean; 11 | import org.apache.activemq.broker.jmx.QueueViewMBean; 12 | 13 | public class Stats { 14 | 15 | public static void main(String[] args) throws Exception { 16 | JMXServiceURL url = new JMXServiceURL( 17 | "service:jmx:rmi:///jndi/rmi://localhost:2011/jmxrmi"); 18 | JMXConnector connector = JMXConnectorFactory.connect(url, null); 19 | connector.connect(); 20 | MBeanServerConnection connection = connector.getMBeanServerConnection(); 21 | ObjectName name = new ObjectName( 22 | "my-broker:BrokerName=localhost,Type=Broker"); 23 | BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler 24 | .newProxyInstance(connection, name, BrokerViewMBean.class, true); 25 | System.out.println("Statistics for broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName()); 26 | System.out.println("\n-----------------\n"); 27 | System.out.println("Total message count: " + mbean.getTotalMessageCount() + "\n"); 28 | System.out.println("Total number of consumers: " + mbean.getTotalConsumerCount()); 29 | System.out.println("Total number of Queues: " + mbean.getQueues().length); 30 | 31 | for (ObjectName queueName : mbean.getQueues()) { 32 | System.out.println(queueName); 33 | QueueViewMBean queueMbean = (QueueViewMBean) MBeanServerInvocationHandler 34 | .newProxyInstance(connection, queueName, 35 | QueueViewMBean.class, true); 36 | System.out.println("\n-----------------\n"); 37 | System.out.println("Statistics for queue " + queueMbean.getName()); 38 | System.out.println("Size: " + queueMbean.getQueueSize()); 39 | System.out.println("Number of consumers: " + queueMbean.getConsumerCount()); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | log4jConfigLocation 10 | /WEB-INF/classes/log4j.xml 11 | 12 | 13 | 14 | org.springframework.web.util.Log4jConfigListener 15 | 16 | 17 | 18 | contextConfigLocation 19 | /WEB-INF/spring/jms-context.xml 20 | 21 | 22 | 23 | org.springframework.web.context.ContextLoaderListener 24 | 25 | 26 | 27 | jms-webapp 28 | org.springframework.web.servlet.DispatcherServlet 29 | 1 30 | 31 | 32 | 33 | jms-webapp 34 | *.html 35 | 36 | 37 | 38 | JMS Connection 39 | jms/ConnectionFactory 40 | org.apache.activemq.ActiveMQConnectionFactory 41 | Container 42 | Shareable 43 | 44 | 45 | 46 | jms/FooQueue 47 | javax.jms.Queue 48 | Container 49 | Shareable 50 | 51 | 52 | 60 | 61 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/advisory/Test.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.advisory; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.MessageConsumer; 7 | import javax.jms.Session; 8 | 9 | import org.apache.activemq.ActiveMQConnectionFactory; 10 | import org.apache.activemq.advisory.AdvisorySupport; 11 | import org.apache.activemq.command.ActiveMQDestination; 12 | 13 | public class Test { 14 | protected static String brokerURL = "tcp://localhost:61616"; 15 | protected static transient ConnectionFactory factory; 16 | protected transient Connection connection; 17 | protected transient Session session; 18 | 19 | private String jobs[] = new String[]{"suspend", "delete"}; 20 | 21 | public Test() throws Exception { 22 | factory = new ActiveMQConnectionFactory(brokerURL); 23 | connection = factory.createConnection(); 24 | connection.start(); 25 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 26 | } 27 | 28 | public static void main(String[] args) throws Exception { 29 | Test advisory = new Test(); 30 | Session session = advisory.getSession(); 31 | for (String job : advisory.jobs) { 32 | 33 | ActiveMQDestination destination = (ActiveMQDestination)session.createQueue("JOBS." + job); 34 | 35 | Destination consumerTopic = AdvisorySupport.getConsumerAdvisoryTopic(destination); 36 | System.out.println("Subscribing to advisory " + consumerTopic); 37 | MessageConsumer consumerAdvisory = session.createConsumer(consumerTopic); 38 | consumerAdvisory.setMessageListener(new ConsumerAdvisoryListener()); 39 | 40 | Destination noConsumerTopic = AdvisorySupport.getNoQueueConsumersAdvisoryTopic(destination); 41 | System.out.println("Subscribing to advisory " + noConsumerTopic); 42 | MessageConsumer noConsumerAdvisory = session.createConsumer(noConsumerTopic); 43 | noConsumerAdvisory.setMessageListener(new NoConsumerAdvisoryListener()); 44 | 45 | } 46 | } 47 | 48 | public Session getSession() { 49 | return session; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch6/spring/SpringPublisher.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch6.spring; 2 | 3 | import java.util.HashMap; 4 | 5 | import javax.jms.Destination; 6 | 7 | import org.springframework.jms.core.JmsTemplate; 8 | 9 | 10 | public class SpringPublisher { 11 | 12 | private JmsTemplate template; 13 | private int count = 10; 14 | private int total; 15 | private Destination[] destinations; 16 | private HashMap creators = new HashMap(); 17 | 18 | public void start() { 19 | while (total < 1000) { 20 | for (int i = 0; i < count; i++) { 21 | sendMessage(); 22 | } 23 | total += count; 24 | System.out.println("Published '" + count + "' of '" + total + "' price messages"); 25 | try { 26 | Thread.sleep(1000); 27 | } catch (InterruptedException x) { 28 | } 29 | } 30 | } 31 | 32 | protected void sendMessage() { 33 | int idx = 0; 34 | while (true) { 35 | idx = (int)Math.round(destinations.length * Math.random()); 36 | if (idx < destinations.length) { 37 | break; 38 | } 39 | } 40 | Destination destination = destinations[idx]; 41 | template.send(destination, getStockMessageCreator(destination)); 42 | } 43 | 44 | private StockMessageCreator getStockMessageCreator(Destination dest) { 45 | if (creators.containsKey(dest)) { 46 | return creators.get(dest); 47 | } else { 48 | StockMessageCreator creator = new StockMessageCreator(dest); 49 | creators.put(dest, creator); 50 | return creator; 51 | } 52 | } 53 | 54 | public JmsTemplate getTemplate() { 55 | return template; 56 | } 57 | 58 | public void setTemplate(JmsTemplate template) { 59 | this.template = template; 60 | } 61 | 62 | public Destination[] getDestinations() { 63 | return destinations; 64 | } 65 | 66 | public void setDestinations(Destination[] destinations) { 67 | this.destinations = destinations; 68 | } 69 | 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch7/spring/SpringPublisher.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch7.spring; 2 | 3 | import java.util.HashMap; 4 | 5 | import javax.jms.Destination; 6 | 7 | import org.springframework.jms.core.JmsTemplate; 8 | 9 | 10 | public class SpringPublisher { 11 | 12 | private JmsTemplate template; 13 | private int count = 10; 14 | private int total; 15 | private Destination[] destinations; 16 | private HashMap creators = new HashMap(); 17 | 18 | public void start() { 19 | while (total < 1000) { 20 | for (int i = 0; i < count; i++) { 21 | sendMessage(); 22 | } 23 | total += count; 24 | System.out.println("Published '" + count + "' of '" + total + "' price messages"); 25 | try { 26 | Thread.sleep(1000); 27 | } catch (InterruptedException x) { 28 | } 29 | } 30 | } 31 | 32 | protected void sendMessage() { 33 | int idx = 0; 34 | while (true) { 35 | idx = (int)Math.round(destinations.length * Math.random()); 36 | if (idx < destinations.length) { 37 | break; 38 | } 39 | } 40 | Destination destination = destinations[idx]; 41 | template.send(destination, getStockMessageCreator(destination)); 42 | } 43 | 44 | private StockMessageCreator getStockMessageCreator(Destination dest) { 45 | if (creators.containsKey(dest)) { 46 | return creators.get(dest); 47 | } else { 48 | StockMessageCreator creator = new StockMessageCreator(dest); 49 | creators.put(dest, creator); 50 | return creator; 51 | } 52 | } 53 | 54 | public JmsTemplate getTemplate() { 55 | return template; 56 | } 57 | 58 | public void setTemplate(JmsTemplate template) { 59 | this.template = template; 60 | } 61 | 62 | public Destination[] getDestinations() { 63 | return destinations; 64 | } 65 | 66 | public void setDestinations(Destination[] destinations) { 67 | this.destinations = destinations; 68 | } 69 | 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch5/activemq-authorization.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 29 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch6/activemq-authorization.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 23 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/activemq.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/resources/activemq.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/resources/activemq.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/resources/activemq.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-geronimo/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | log4jConfigLocation 10 | /WEB-INF/classes/log4j.xml 11 | 12 | 13 | 14 | org.springframework.web.util.Log4jConfigListener 15 | 16 | 17 | 18 | contextConfigLocation 19 | /WEB-INF/spring/jms-context.xml 20 | 21 | 22 | 23 | org.springframework.web.context.ContextLoaderListener 24 | 25 | 26 | 27 | jms-webapp 28 | org.springframework.web.servlet.DispatcherServlet 29 | 1 30 | 31 | 32 | 33 | jms-webapp 34 | *.html 35 | 36 | 37 | 38 | JMS Connection 39 | jms/ConnectionFactory 40 | javax.jms.ConnectionFactory 41 | Container 42 | Shareable 43 | 44 | 45 | 46 | jms/FooQueue 47 | javax.jms.Queue 48 | Produces 49 | jms/FooQueue 50 | 51 | 52 | 60 | 61 | 66 | 67 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-local/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | log4jConfigLocation 10 | /WEB-INF/classes/log4j.xml 11 | 12 | 13 | 14 | org.springframework.web.util.Log4jConfigListener 15 | 16 | 17 | 18 | contextConfigLocation 19 | /WEB-INF/spring/jms-context.xml 20 | 21 | 22 | 23 | org.springframework.web.context.ContextLoaderListener 24 | 25 | 26 | 27 | jms-webapp 28 | org.springframework.web.servlet.DispatcherServlet 29 | 1 30 | 31 | 32 | 33 | jms-webapp 34 | *.html 35 | 36 | 37 | 38 | JMS Connection 39 | jms/ConnectionFactory 40 | javax.jms.ConnectionFactory 41 | Container 42 | Shareable 43 | 44 | 45 | 46 | jms/FooQueue 47 | javax.jms.Queue 48 | Produces 49 | jms/FooQueue 50 | 51 | 52 | 60 | 61 | 66 | 67 | -------------------------------------------------------------------------------- /examples/src/main/java/org/apache/activemq/book/ch14/advisory/Advisory.java: -------------------------------------------------------------------------------- 1 | package org.apache.activemq.book.ch14.advisory; 2 | 3 | import javax.jms.Connection; 4 | import javax.jms.ConnectionFactory; 5 | import javax.jms.Destination; 6 | import javax.jms.Message; 7 | import javax.jms.MessageConsumer; 8 | import javax.jms.MessageListener; 9 | import javax.jms.Session; 10 | 11 | import org.apache.activemq.ActiveMQConnectionFactory; 12 | import org.apache.activemq.advisory.AdvisorySupport; 13 | import org.apache.activemq.command.ActiveMQDestination; 14 | import org.apache.activemq.command.ActiveMQMessage; 15 | import org.apache.activemq.command.CommandTypes; 16 | import org.apache.activemq.command.ConsumerId; 17 | import org.apache.activemq.command.ConsumerInfo; 18 | import org.apache.activemq.command.DataStructure; 19 | import org.apache.activemq.command.RemoveInfo; 20 | 21 | public class Advisory { 22 | 23 | protected static String brokerURL = "tcp://localhost:61616"; 24 | protected static transient ConnectionFactory factory; 25 | protected transient Connection connection; 26 | protected transient Session session; 27 | 28 | public Advisory() throws Exception { 29 | factory = new ActiveMQConnectionFactory(brokerURL); 30 | connection = factory.createConnection(); 31 | connection.start(); 32 | session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 33 | } 34 | 35 | public static void main(String[] args) throws Exception { 36 | Advisory advisory = new Advisory(); 37 | Session session = advisory.getSession(); 38 | for (String stock : args) { 39 | 40 | ActiveMQDestination destination = (ActiveMQDestination)session.createTopic("STOCKS." + stock); 41 | 42 | Destination consumerTopic = AdvisorySupport.getConsumerAdvisoryTopic(destination); 43 | System.out.println("Subscribing to advisory " + consumerTopic); 44 | MessageConsumer consumerAdvisory = session.createConsumer(consumerTopic); 45 | consumerAdvisory.setMessageListener(new ConsumerAdvisoryListener()); 46 | 47 | Destination noConsumerTopic = AdvisorySupport.getNoTopicConsumersAdvisoryTopic(destination); 48 | System.out.println("Subscribing to advisory " + noConsumerTopic); 49 | MessageConsumer noConsumerAdvisory = session.createConsumer(noConsumerTopic); 50 | noConsumerAdvisory.setMessageListener(new NoConsumerAdvisoryListener()); 51 | 52 | } 53 | } 54 | 55 | public Session getSession() { 56 | return session; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-jboss/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | log4jConfigLocation 10 | /WEB-INF/classes/log4j.xml 11 | 12 | 13 | 14 | org.springframework.web.util.Log4jConfigListener 15 | 16 | 17 | 18 | contextConfigLocation 19 | /WEB-INF/spring/jms-context.xml 20 | 21 | 22 | 23 | contextClass 24 | 25 | org.jboss.spring.vfs.context.VFSXmlWebApplicationContext 26 | 27 | 28 | 29 | 30 | org.springframework.web.context.ContextLoaderListener 31 | 32 | 33 | 34 | jms-webapp 35 | org.springframework.web.servlet.DispatcherServlet 36 | 37 | contextClass 38 | 39 | org.jboss.spring.vfs.context.VFSXmlWebApplicationContext 40 | 41 | 42 | 1 43 | 44 | 45 | 46 | jms-webapp 47 | *.html 48 | 49 | 50 | 51 | JMS Connection 52 | jms/ConnectionFactory 53 | javax.jms.ConnectionFactory 54 | Container 55 | Shareable 56 | 57 | 58 | 59 | jms/FooQueue 60 | javax.jms.Queue 61 | Container 62 | Shareable 63 | 64 | 65 | 70 | 71 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch7/pure-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | tcp://localhost:61616 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /examples/chapter8/jms-webapp-global/src/main/webapp/WEB-INF/spring/jms-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 27 | 28 | 31 | 32 | 36 | 37 | 40 | 41 | 43 | 44 | 48 | 49 | 50 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/src/main/resources/org/apache/activemq/book/ch7/spring-client.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | --------------------------------------------------------------------------------