diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2008-11-24 12:46:34 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2008-11-24 12:46:34 +0000 |
| commit | 4e3809074bb2eedf6b170d9a491a25335cf33eb7 (patch) | |
| tree | c416ef06f410730a1f1a8640ad24c7c11bff9374 /java/client/example | |
| parent | f7337061c02d92b70441c1194e96e4b771befa26 (diff) | |
| download | qpid-python-4e3809074bb2eedf6b170d9a491a25335cf33eb7.tar.gz | |
QPID-1480 : Updated Simple Request Response code
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@720181 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/example')
| -rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java | 15 | ||||
| -rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java | 29 |
2 files changed, 32 insertions, 12 deletions
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java b/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java index d78757801e..8a0ff88448 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java @@ -53,8 +53,6 @@ public class Client implements MessageListener private InitialContext _ctx; - private static boolean TRANSACTED = true; - private static final boolean NOT_TRANSACTED = !TRANSACTED; private CountDownLatch _shutdownHook = new CountDownLatch(1); public Client() @@ -71,7 +69,7 @@ public class Client implements MessageListener { connection = ((ConnectionFactory) lookupJNDI(CONNECTION_JNDI_NAME)).createConnection(); - session = connection.createSession(NOT_TRANSACTED, Session.AUTO_ACKNOWLEDGE); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination requestQueue = (Queue) lookupJNDI(QUEUE_JNDI_NAME); @@ -131,6 +129,15 @@ public class Client implements MessageListener //Handle the exception appropriately } + try + { + System.out.println("Sent Request Message ID :" + txtMessage.getJMSMessageID()); + } + catch (JMSException e) + { + //Handle exception more appropriately. + } + //Wait for the return message to arrive try { @@ -161,7 +168,7 @@ public class Client implements MessageListener */ public void onMessage(Message message) { - String messageText = null; + String messageText; try { if (message instanceof TextMessage) diff --git a/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java b/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java index 8cf9d2d26e..63c7e95705 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java @@ -37,10 +37,15 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import java.util.Properties; import java.util.concurrent.CountDownLatch; +import java.io.BufferedReader; +import java.io.BufferedInputStream; +import java.io.Reader; +import java.io.InputStreamReader; +import java.io.IOException; public class Server implements MessageListener { - final String BROKER = "tcp://localhost:1234"; + final String BROKER = "localhost"; final String INITIAL_CONTEXT_FACTORY = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; @@ -50,9 +55,6 @@ public class Server implements MessageListener final String QUEUE_JNDI_NAME = "queue"; final String QUEUE_NAME = "example.RequestQueue"; - private static boolean TRANSACTED = true; - private static final boolean NOT_TRANSACTED = !TRANSACTED; - private InitialContext _ctx; private Session _session; @@ -68,7 +70,7 @@ public class Server implements MessageListener { connection = ((ConnectionFactory) lookupJNDI(CONNECTION_JNDI_NAME)).createConnection(); - _session = connection.createSession(NOT_TRANSACTED, Session.AUTO_ACKNOWLEDGE); + _session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination requestQueue = (Queue) lookupJNDI(QUEUE_JNDI_NAME); @@ -92,6 +94,8 @@ public class Server implements MessageListener return; } + System.out.println("Server process started and waiting for messages."); + //Wait to process an single message then quit. try { @@ -135,10 +139,19 @@ public class Server implements MessageListener //Set the correlation ID from the received message to be the correlation id of the response message //this lets the client identify which message this is a response to if it has more than //one outstanding message to the server - response.setJMSCorrelationID(message.getJMSCorrelationID()); + response.setJMSCorrelationID(message.getJMSMessageID()); + + try + { + System.out.println("Received message press enter to send response...."); + new BufferedReader(new InputStreamReader(System.in)).readLine(); + } + catch (IOException e) + { + //Error attemptying to pause + } - //Send the response to the Destination specified by the JMSReplyTo field of the received message, - //this is presumably a temporary queue created by the client + //Send the response to the Destination specified by the JMSReplyTo field of the received message. _replyProducer.send(message.getJMSReplyTo(), response); } catch (JMSException e) |
