jstrachan 2002/10/07 03:38:23
Modified: messenger/src/conf subscribe.xml MessengerSpiritWave.xml
messenger maven.xml
messenger/src/java/org/apache/commons/messagelet Main.java
Added: messenger/src/test/org/apache/commons/messenger
LoggingMDO.java
Log:
Added a simple example to the maven build for consuming JMS messages using the
simple command line Messagelet engine and a simple LoggingMDO.
Revision Changes Path
1.9 +11 -5 jakarta-commons-sandbox/messenger/src/conf/subscribe.xml
Index: subscribe.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/conf/subscribe.xml,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- subscribe.xml 9 Jul 2002 11:53:35 -0000 1.8
+++ subscribe.xml 7 Oct 2002 10:38:23 -0000 1.9
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<subscriptions>
+ <!-- a simple echo consumer -->
+ <subscription connection="queue" subject="echo.queue">
+ <listener className="org.apache.commons.messenger.LoggingMDO"/>
+ </subscription>
+
<!-- bridge to another JMS provider -->
<subscription connection="queue" subject="my.input2" selector="b='12'">
<bridge outputConnection="queue" outputSubject="my.output"/>
@@ -9,12 +14,12 @@
<!-- distribute messages to multiple output queues -->
<subscription connection="queue" subject="my.input">
<distributeBridge outputConnection="queue">
- <subject>output.A</subject>
- <subject>output.B</subject>
- <subject>output.C</subject>
- <subject>output.D</subject>
+ <subject>output.A</subject>
+ <subject>output.B</subject>
+ <subject>output.C</subject>
+ <subject>output.D</subject>
</distributeBridge>
- </subscription>
+ </subscription>
<!-- consume the output queues and report throughput -->
@@ -30,6 +35,7 @@
<subscription connection="queue" subject="output.D">
<stopWatch groupSize="100"/>
</subscription>
+
1.5 +2 -2
jakarta-commons-sandbox/messenger/src/conf/MessengerSpiritWave.xml
Index: MessengerSpiritWave.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/conf/MessengerSpiritWave.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MessengerSpiritWave.xml 8 Jul 2002 16:19:05 -0000 1.4
+++ MessengerSpiritWave.xml 7 Oct 2002 10:38:23 -0000 1.5
@@ -2,11 +2,11 @@
<manager>
<messenger name="topic">
- <factory className="com.spirit.messenger.WaveTopicSessionFactory"
transacted="true">
+ <factory className="com.spirit.messenger.WaveTopicSessionFactory">
</factory>
</messenger>
<messenger name="queue">
- <factory className="com.spirit.messenger.WaveQueueSessionFactory"
transacted="true">
+ <factory className="com.spirit.messenger.WaveQueueSessionFactory">
</factory>
</messenger>
</manager>
1.3 +9 -4 jakarta-commons-sandbox/messenger/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/maven.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- maven.xml 8 Jul 2002 15:15:24 -0000 1.2
+++ maven.xml 7 Oct 2002 10:38:23 -0000 1.3
@@ -1,15 +1,19 @@
<project default="java:jar" xmlns:j="jelly:core">
- <goal name="set.classpath" prereqs="java:compile">
+ <goal name="set.classpath" prereqs="java:compile, test:compile">
<echo>
Using JMS from lib dir ${jms.lib.dir} and config dir ${jms.classes.dir}
+ Connecting via ${messenger.xml}
</echo>
<path id="jms.classpath">
+ <!--
<pathelement path="target/classes"/>
+ -->
+ <pathelement path="target/test-classes"/>
<pathelement path="${maven.build.dest}"/>
- <path refid="maven.dependency.classpath"/>
+ <path refid="maven.dependency.classpath"/>
<!-- add the JARs required for a pluggable JMS provider -->
<pathelement path="${jms.classes.dir}"/>
@@ -21,7 +25,8 @@
</goal>
<!-- runs a sample number of subscriptions -->
- <goal name="demo.subscribe" prereqs="set.classpath">
+ <goal name="demo:subscribe" prereqs="set.classpath"
+ description="Subscribes to various destinations waiting for JMS messages">
<java classname="org.apache.commons.messagelet.Main" fork="yes">
<classpath refid="jms.classpath"/>
@@ -37,7 +42,7 @@
<java classname="org.apache.commons.messenger.tool.Producer" fork="yes">
<classpath refid="jms.classpath"/>
<arg value="queue"/>
- <arg value="my.input"/>
+ <arg value="echo.queue"/>
<arg value="src/conf/sampleMessage.txt"/>
<sysproperty key="org.apache.commons.messenger" value="${messenger.xml}"/>
</java>
1.1
jakarta-commons-sandbox/messenger/src/test/org/apache/commons/messenger/LoggingMDO.java
Index: LoggingMDO.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
* $Id: LoggingMDO.java,v 1.4 2002/05/17 15:05:46 jstrachan Exp $
*/
package org.apache.commons.messenger;
import javax.jms.Message;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.messagelet.MessengerMDO;
import org.apache.commons.messenger.Messenger;
/**
* <p><code>LoggingMDO</code> is a simple MDO which
* logs the fact that it consumed a message.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.4 $
*/
public class LoggingMDO extends MessengerMDO {
/** Logger to which logging messages will go */
private static final Log log = LogFactory.getLog(LoggingMDO.class);
public void onMessage(Message message) {
log.info( "Received message: " + message );
System.out.println( "Received message: " + message );
}
}
1.5 +24 -3
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/Main.java
Index: Main.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/Main.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Main.java 14 Aug 2002 14:36:12 -0000 1.4
+++ Main.java 7 Oct 2002 10:38:23 -0000 1.5
@@ -57,7 +57,7 @@
private String subscriptionsConfig = "subscriptions.xml";
/** Should we use a stopwatch to output performance metrics */
- private boolean useStopWatch = true;
+ private boolean useStopWatch = false;
public static void main(String[] args) {
@@ -88,12 +88,12 @@
/**
* Starts all the JMS connections and consumes JMS messages,
* passing them onto the MessageListener and Message Driven Objects
- * */
+ */
public void run() throws Exception {
// force lazy construction
getMessengerManager();
-
+
// load the subscriptions....
subscriptionList = createSubscriptionList();
subscribe( subscriptionList );
@@ -109,7 +109,10 @@
log.error( "Caught exception trying to start messenger: " + name +
". Exception: " + e, e );
}
}
+
+ //waitForever();
}
+
public Messenger getMessenger(String name) throws JMSException {
return getMessengerManager().getMessenger( name );
@@ -204,6 +207,8 @@
messenger.addListener( destination, listener );
}
+
+ log.info( "Subscribed with listener: " + listener );
}
protected MessengerManager createMessengerManager() throws JMSException {
@@ -257,4 +262,20 @@
return listener;
}
+ /**
+ * This method blocks the current thread indefinitely until the JVM is
terminated.
+ */
+ protected void waitForever() {
+ Object lock = new Object();
+ synchronized (lock) {
+ while (true) {
+ try {
+ lock.wait();
+ }
+ catch (Exception e) {
+ log.warn( "Main thread interupted: " + e, e );
+ }
+ }
+ }
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>