camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r666776 - in /activemq/camel/trunk/examples/camel-example-spring-jms: README.txt pom.xml src/main/java/org/apache/camel/example/client/CamelClient.java src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
Date Wed, 11 Jun 2008 18:33:56 GMT
Author: davsclaus
Date: Wed Jun 11 11:33:55 2008
New Revision: 666776

URL: http://svn.apache.org/viewvc?rev=666776&view=rev
Log:
CAMEL-590: Added CamelClientEndpoint for Message Endpoint EIP pattern style

Added:
    activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
      - copied, changed from r666745, activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
Modified:
    activemq/camel/trunk/examples/camel-example-spring-jms/README.txt
    activemq/camel/trunk/examples/camel-example-spring-jms/pom.xml
    activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java

Modified: activemq/camel/trunk/examples/camel-example-spring-jms/README.txt
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring-jms/README.txt?rev=666776&r1=666775&r2=666776&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring-jms/README.txt (original)
+++ activemq/camel/trunk/examples/camel-example-spring-jms/README.txt Wed Jun 11 11:33:55
2008
@@ -11,9 +11,14 @@
 
 The Server comes in two flavors:
 - Normal that acts as a JMS broker
-- As Normal plus an AOP aspect that does audit trails of the invocation
+- As normal plus an AOP aspect that does audit trails of the invocation
 of the business service and uses Camel for mediation of the storage of the audit message.
 
+And for the Client we have a total of three flavors:
+- Normal use the ProducerTemplate ala Spring Template style
+- Using Spring Remoting for powefull "Client doesnt know at all its a remote call"
+- And using the Message Endpoint pattern using the neutral Camel API
+
 For the latest & greatest documentation on how to use this example please see:
   http://cwiki.apache.org/CAMEL/tutorial-jmsremoting.html
 
@@ -25,6 +30,7 @@
   mvn exec:java -PCamelServerAOP
   mvn exec:java -PCamelClient
   mvn exec:java -PCamelClientRemoting
+  mvn exec:java -PCamelClientEndpoint
 
 To stop the example hit ctrl + c
 

Modified: activemq/camel/trunk/examples/camel-example-spring-jms/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring-jms/pom.xml?rev=666776&r1=666775&r2=666776&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring-jms/pom.xml (original)
+++ activemq/camel/trunk/examples/camel-example-spring-jms/pom.xml Wed Jun 11 11:33:55 2008
@@ -123,6 +123,13 @@
                 <target.main.class>org.apache.camel.example.client.CamelClientRemoting</target.main.class>
             </properties>
         </profile>
+        <profile>
+            <id>CamelClientEndpoint</id>
+            <properties>
+                <!-- we start using our own class to control what we do in the main -->
+                <target.main.class>org.apache.camel.example.client.CamelClientEndpoint</target.main.class>
+            </properties>
+        </profile>
     </profiles>
     <build>
         <plugins>

Modified: activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java?rev=666776&r1=666775&r2=666776&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
(original)
+++ activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
Wed Jun 11 11:33:55 2008
@@ -34,6 +34,8 @@
         System.out.println("Notice this client requires that the CamelServer is already running!");
 
         ApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
+
+        // get the camel template for Spring template style sending of messages (= producer)
         ProducerTemplate camelTemplate = (ProducerTemplate) context.getBean("camelTemplate");
 
         System.out.println("Invoking the multiply with 22");

Copied: activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
(from r666745, activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java?p2=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java&p1=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java&r1=666745&r2=666776&rev=666776&view=diff
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
(original)
+++ activemq/camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
Wed Jun 11 11:33:55 2008
@@ -16,31 +16,56 @@
  */
 package org.apache.camel.example.client;
 
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.ProducerTemplate;
 import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Producer;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * Client that uses the {@link ProducerTemplate} to easily exchange messages with the Server.
+ * Client that uses the <a href="http://activemq.apache.org/camel/message-endpoint.html">Mesage
Endpoint</a>
+ * pattern to easily exchange messages with the Server.
+ * <p/>
+ * Notice this very same API can use for all components in Camel, so if we were using TCP
communication instead
+ * of JMS messaging we could just use <code>camel.getEndpoint("mina:tcp://someserver:port")</code>.
  * <p/>
  * Requires that the JMS broker is running, as well as CamelServer
  */
-public final class CamelClient {
+public final class CamelClientEndpoint {
 
     // START SNIPPET: e1
     public static void main(final String[] args) throws Exception {
         System.out.println("Notice this client requires that the CamelServer is already running!");
 
         ApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
-        ProducerTemplate camelTemplate = (ProducerTemplate) context.getBean("camelTemplate");
+        CamelContext camel = (CamelContext) context.getBean("camel");
+
+        // get the endpoint from the camel context
+        Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");
+
+        // create the exchange used for the communication
+        // we use the in out pattern for a synchronized exchange where we expect a response
+        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
+        // set the input on the in body
+        exchange.getIn().setBody("11");
+
+        // to send the exchange we need an producer to do it for us
+        Producer producer = endpoint.createProducer();
+        // start the producer so it can operate
+        producer.start();
+
+        // let the producer process the exchange where it does all the work in this oneline
of code
+        System.out.println("Invoking the multiply with 11");
+        producer.process(exchange);
 
-        System.out.println("Invoking the multiply with 22");
-        // as opposed to the CamelClientRemoting example we need to define the service URI
in this java code 
-        int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut,
22);
+        // get the response from the out body and cast it to an integer
+        int response = exchange.getOut().getBody(Integer.class);
         System.out.println("... the result is: " + response);
 
+        // stop and exit the client
+        producer.stop();
         System.exit(0);
     }
     // END SNIPPET: e1



Mime
View raw message