diff options
author | Arnaud Simon <arnaudsimon@apache.org> | 2007-12-07 17:14:44 +0000 |
---|---|---|
committer | Arnaud Simon <arnaudsimon@apache.org> | 2007-12-07 17:14:44 +0000 |
commit | 237c3437a5a4b68c483af77c5d1346104ca404a0 (patch) | |
tree | 5a17816d7d5bd72a854e984055aff73ae45d5d1a | |
parent | c78dcd3c7a317a67e030318c76e8f622362b9a33 (diff) | |
download | qpid-python-237c3437a5a4b68c483af77c5d1346104ca404a0.tar.gz |
changed for accepting messages from python and c++
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@602154 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java | 2 | ||||
-rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java | 8 | ||||
-rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java (renamed from java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java) | 41 | ||||
-rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java | 152 | ||||
-rw-r--r-- | java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java (renamed from java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java) | 54 |
5 files changed, 60 insertions, 197 deletions
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java index 1eb207ada5..6b82bd469b 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java @@ -49,7 +49,7 @@ abstract public class BaseExample private static final String DEFAULT_CONNECTION_FACTORY_NAME = "ConnectionFactory"; /* Default number of messages to process. */ - private static final int DEFAULT_NUMBER_MESSAGES = 1; + private static final int DEFAULT_NUMBER_MESSAGES = 10; /* JNDI provider URL. */ private String _providerURL; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java index 5178051613..35f4b87cd3 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java @@ -79,23 +79,19 @@ public class Producer extends BaseExample // Create a Message TextMessage message; System.out.println(CLASS + ": Creating a TestMessage to send to the destination"); - message = session.createTextMessage(); - - // Set a property for illustrative purposes - //message.setDoubleProperty("Amount", 10.1); // Loop to publish the requested number of messages. for (int i = 1; i < getNumberMessages() + 1; i++) { // NOTE: We have NOT HAD TO START THE CONNECTION TO BEGIN SENDING messages, // this is different to the consumer end as a CONSUMERS CONNECTIONS MUST BE STARTED BEFORE RECEIVING. - message.setText("Message " + i); + message = session.createTextMessage("Message " + i); System.out.println(CLASS + ": Sending message: " + i); messageProducer.send(message, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); } // And send a final message to indicate termination. - message.setText("That's all, folks!"); + message = session.createTextMessage("That's all, folks!"); messageProducer.send(message, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); // Close the connection to the broker diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java index 813832b5a9..78f91a677d 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java @@ -28,23 +28,23 @@ import javax.jms.*; * This example illustrates the use of the JMS utility class <code>QueueRequestor</code> * which provides a synchronous RPC-like abstraction using temporary destinations * to deliver responses back to the client. - * + * <p/> * <p>Run with <code>-help</code> argument for a description of command line arguments. - * */ -public class P2PRequestor extends BaseExample +public class Client extends BaseExample { /* Used in log output. */ - private static final String CLASS = "P2PRequestor"; + private static final String CLASS = "Client"; /* The queue name */ private String _queueName; /** - * Create a P2PRequestor client. + * Create a Client client. + * * @param args Command line arguments. */ - public P2PRequestor(String[] args) + public Client(String[] args) { super(CLASS, args); _queueName = _argProcessor.getStringArgument("-queueName"); @@ -52,13 +52,14 @@ public class P2PRequestor extends BaseExample /** * Run the message requestor example. + * * @param args Command line arguments. */ public static void main(String[] args) { - _options.put("-queueName", "The queue name"); - _defaults.put("-queueName", "message_queue"); - P2PRequestor requestor = new P2PRequestor(args); + _options.put("-queueName", "The queue name"); + _defaults.put("-queueName", "request"); + Client requestor = new Client(args); requestor.runTest(); } @@ -74,7 +75,8 @@ public class P2PRequestor extends BaseExample // As this application is using a MessageConsumer we need to set an ExceptionListener on the connection // so that errors raised within the JMS client library can be reported to the application - System.out.println(CLASS + ": Setting an ExceptionListener on the connection as sample uses a MessageConsumer"); + System.out.println( + CLASS + ": Setting an ExceptionListener on the connection as sample uses a MessageConsumer"); connection.setExceptionListener(new ExceptionListener() { @@ -109,7 +111,7 @@ public class P2PRequestor extends BaseExample request = session.createTextMessage(); - // Get the number of times that this sample should request service + // Get the number of times that this sample should request service for (int i = 0; i < getNumberMessages(); i++) { request = session.createTextMessage("Twas brillig, and the slithy toves"); @@ -126,8 +128,8 @@ public class P2PRequestor extends BaseExample // And send a final message to indicate termination. request.setText("That's all, folks!"); MessageProducer messageProducer = session.createProducer(destination); - messageProducer.send(request, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - + messageProducer.send(request, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); + // Close the connection to the server System.out.println(CLASS + ": Closing connection"); connection.close(); @@ -142,15 +144,24 @@ public class P2PRequestor extends BaseExample } } - private void sendReceive(TextMessage request, QueueRequestor requestor) throws JMSException + private void sendReceive(TextMessage request, QueueRequestor requestor) throws JMSException { Message response; response = requestor.request(request); System.out.println(CLASS + ": \tRequest Content= " + request.getText()); // Print out the details of the response received + String text; if (response instanceof TextMessage) { - System.out.println(CLASS + ": \t Response Content= " + ((TextMessage) response).getText()); + text = ((TextMessage) response).getText(); } + else + { + byte[] body = new byte[(int) ((BytesMessage) response).getBodyLength()]; + ((BytesMessage) response).readBytes(body); + text = new String(body); + } + System.out.println(CLASS + ": \tResponse Content= " + text); } } + diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java deleted file mode 100644 index b61d9086d1..0000000000 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.example.jmsexample.requestResponse; - -import org.apache.qpid.example.jmsexample.common.BaseExample; - -import javax.jms.*; - -/** - * This example illustrates the use of the JMS utility class <code>TopicRequestor</code> - * which provides a synchronous RPC-like abstraction using temporary destinations - * to deliver responses back to the client. - */ -public class PubSubRequestor extends BaseExample -{ - /* Used in log output. */ - private static final String CLASS = "PubSubRequestor"; - - /* The topic name */ - private String _topicName; - - /** - * Create a PubSubRequestor client. - * - * @param args Command line arguments. - */ - public PubSubRequestor(String[] args) - { - super(CLASS, args); - _topicName = _argProcessor.getStringArgument("-topicName"); - } - - /** - * Run the message requestor example. - * - * @param args Command line arguments. - */ - public static void main(String[] args) - { - _options.put("-topicName", "The topic name"); - _defaults.put("-topicName", "world"); - PubSubRequestor requestor = new PubSubRequestor(args); - requestor.runTest(); - } - - /** - * Start the example. - */ - private void runTest() - { - try - { - // Declare the connection - TopicConnection connection = (TopicConnection) getConnection(); - - // As this application is using a MessageConsumer we need to set an ExceptionListener on the connection - // so that errors raised within the JMS client library can be reported to the application - System.out.println( - CLASS + ": Setting an ExceptionListener on the connection as sample uses a MessageConsumer"); - - connection.setExceptionListener(new ExceptionListener() - { - public void onException(JMSException jmse) - { - // The connection may have broken invoke reconnect code if available. - // The connection may have broken invoke reconnect code if available. - System.err.println(CLASS + ": The sample received an exception through the ExceptionListener"); - System.exit(0); - } - }); - - // Create a session on the connection. - System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); - TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); - - // Lookup the destination - System.out.println(CLASS + ": Looking up topic with name: " + _topicName); - Topic destination = session.createTopic(_topicName); - - // Create a TopicRequestor - System.out.println(CLASS + ": Creating a TopicRequestor"); - TopicRequestor requestor = new TopicRequestor(session, destination); - - // Now start the connection - System.out.println(CLASS + ": Starting connection"); - connection.start(); - - // Create a message to send as a request for service - TextMessage request; - request = session.createTextMessage(); - - // Get the number of times that this sample should request service - for (int i = 0; i < getNumberMessages(); i++) - { - request = session.createTextMessage("Twas brillig, and the slithy toves"); - sendReceive(request, requestor); - request = session.createTextMessage("Did gire and gymble in the wabe"); - sendReceive(request, requestor); - request = session.createTextMessage("All mimsy were the borogroves,"); - sendReceive(request, requestor); - request = session.createTextMessage("And the mome raths outgrabe."); - sendReceive(request, requestor); - } - // And send a final message to indicate termination. - request.setText("That's all, folks!"); - MessageProducer messageProducer = session.createProducer(destination); - messageProducer.send(request, getDeliveryMode(), Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); - - // Close the connection to the server - System.out.println(CLASS + ": Closing connection"); - connection.close(); - - // Close the JNDI reference - System.out.println(CLASS + ": Closing JNDI context"); - getInitialContext().close(); - } - catch (Exception exp) - { - System.err.println(CLASS + ": Caught an Exception: " + exp); - } - } - - private void sendReceive(TextMessage request, TopicRequestor requestor) throws JMSException - { - Message response; - response = requestor.request(request); - System.out.println(CLASS + ": \tRequest Content= " + request.getText()); - // Print out the details of the response received - if (response instanceof TextMessage) - { - System.out.println(CLASS + ": \t Response Content= " + ((TextMessage) response).getText()); - } - } -} diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java index cc5d35d778..4c0c47f7b4 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java @@ -30,10 +30,10 @@ import javax.jms.*; * received message has a ReplyTo header then a new response message is sent * to that specified destination. */ -public class MessageMirror extends BaseExample +public class Server extends BaseExample { /* Used in log output. */ - private static final String CLASS = "MessageMirror"; + private static final String CLASS = "Server"; /* The destination type */ private String _destinationType; @@ -42,11 +42,11 @@ public class MessageMirror extends BaseExample private String _destinationName; /** - * Create a MessageMirror client. + * Create a Server client. * * @param args Command line arguments. */ - public MessageMirror(String[] args) + public Server(String[] args) { super(CLASS, args); _destinationType = _argProcessor.getStringArgument("-destinationType"); @@ -63,9 +63,9 @@ public class MessageMirror extends BaseExample _options.put("-destinationType", "Destination Type: queue/topic"); _defaults.put("-destinationType", "queue"); _options.put("-destinationName", "Destination Name"); - _defaults.put("-destinationName", "message_queue"); - MessageMirror messageMirror = new MessageMirror(args); - messageMirror.runTest(); + _defaults.put("-destinationName", "request"); + Server server = new Server(args); + server.runTest(); } /** @@ -140,30 +140,38 @@ public class MessageMirror extends BaseExample requestMessage = messageConsumer.receive(); - // Print out the details of the just received message - System.out.println(CLASS + ": Message received:"); - + String text; if (requestMessage instanceof TextMessage) { - if (((TextMessage) requestMessage).getText().equals("That's all, folks!")) - { - System.out.println("Received final message for " + destination); - end = true; - } - System.out.println("\tContents = " + ((TextMessage) requestMessage).getText()); + text = ((TextMessage) requestMessage).getText(); + } + else + { + byte[] body = new byte[(int) ((BytesMessage) requestMessage).getBodyLength()]; + ((BytesMessage) requestMessage).readBytes(body); + text = new String(body); + } + + + if (text.equals("That's all, folks!")) + { + System.out.println(CLASS + ": Received final message for " + destination); + end = true; + } + else + { + System.out.println(CLASS + ": \tContents = " + text); } // Now bounce the message if a ReplyTo header was set. if (requestMessage.getJMSReplyTo() != null) { System.out.println(CLASS + ": Activating response queue listener for: " + destination); - responseMessage = - session.createTextMessage(); - if (requestMessage instanceof TextMessage) - { - responseMessage.setText(((TextMessage) requestMessage).getText().toUpperCase()); - System.out.println(CLASS + ": \tResponse = " + responseMessage.getText()); - } + responseMessage = session.createTextMessage(); + + responseMessage.setText(text.toUpperCase()); + System.out.println(CLASS + ": \tResponse = " + responseMessage.getText()); + messageProducer = session.createProducer(requestMessage.getJMSReplyTo()); messageProducer.send(responseMessage); } |