You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2019/09/25 11:52:19 UTC
[camel] branch master updated: cleanup camel-example-spring-jms a
bit
This is an automated email from the ASF dual-hosted git repository.
bvahdat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new f297d70 cleanup camel-example-spring-jms a bit
f297d70 is described below
commit f297d7042e1ef6ad93b44eda153d2dd1f67e80b5
Author: Babak Vahdat <bv...@apache.org>
AuthorDate: Wed Sep 25 13:52:09 2019 +0200
cleanup camel-example-spring-jms a bit
---
.../java/org/apache/camel/example/client/CamelClient.java | 15 +++++++++++----
.../apache/camel/example/client/CamelClientEndpoint.java | 13 +++++++++----
.../apache/camel/example/client/CamelClientRemoting.java | 13 ++++++++++---
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
index 0d35295..ccc057a 100644
--- a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
+++ b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClient.java
@@ -19,6 +19,8 @@ package org.apache.camel.example.client;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -28,23 +30,28 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* Requires that the JMS broker is running, as well as CamelServer
*/
public final class CamelClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CamelClient.class);
+
private CamelClient() {
// Helper class
}
// 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!");
+ LOG.info("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
// get the camel template for Spring template style sending of messages (= producer)
ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
- System.out.println("Invoking the multiply with 22");
+ LOG.info("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);
- System.out.println("... the result is: " + response);
+ int response = camelTemplate.requestBody("jms:queue:numbers", 22, int.class);
+
+ LOG.info("... the result is: {}", response);
// we're done so let's properly close the application context
IOHelper.close(context);
diff --git a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
index 3cd5f51..7240a02 100644
--- a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
+++ b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientEndpoint.java
@@ -22,6 +22,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Producer;
import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -35,13 +37,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* Requires that the JMS broker is running, as well as CamelServer
*/
public final class CamelClientEndpoint {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CamelClientEndpoint.class);
+
private CamelClientEndpoint() {
//Helper class
}
// 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!");
+ LOG.info("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
CamelContext camel = context.getBean("camel-client", CamelContext.class);
@@ -62,12 +67,12 @@ public final class CamelClientEndpoint {
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");
+ LOG.info("Invoking the multiply with 11");
producer.process(exchange);
// 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);
+ int response = exchange.getMessage().getBody(int.class);
+ LOG.info("... the result is: {}", response);
// stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly
// closed, making this client not to try any further reads for the replies from the server
diff --git a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientRemoting.java b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientRemoting.java
index 8b400cd..78582af 100644
--- a/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientRemoting.java
+++ b/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/client/CamelClientRemoting.java
@@ -18,6 +18,8 @@ package org.apache.camel.example.client;
import org.apache.camel.example.server.Multiplier;
import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -27,13 +29,16 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* Requires that the JMS broker is running, as well as CamelServer
*/
public final class CamelClientRemoting {
+
+ private static final Logger LOG = LoggerFactory.getLogger(CamelClientRemoting.class);
+
private CamelClientRemoting() {
//Helper class
}
// START SNIPPET: e1
public static void main(final String[] args) {
- System.out.println("Notice this client requires that the CamelServer is already running!");
+ LOG.info("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
// just get the proxy to the service and we as the client can use the "proxy" as it was
@@ -41,9 +46,11 @@ public final class CamelClientRemoting {
// to the remote ActiveMQ server and fetch the response.
Multiplier multiplier = context.getBean("multiplierProxy", Multiplier.class);
- System.out.println("Invoking the multiply with 33");
+ LOG.info("Invoking the multiply with 33");
+
int response = multiplier.multiply(33);
- System.out.println("... the result is: " + response);
+
+ LOG.info("... the result is: {}", response);
// we're done so let's properly close the application context
IOHelper.close(context);