summaryrefslogtreecommitdiff
path: root/qpid/cpp/tests/client_test.cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2007-04-02 11:40:48 +0000
committerAndrew Stitcher <astitcher@apache.org>2007-04-02 11:40:48 +0000
commit9ecd69ebc88fb5d82a693e51eef0475c1a6b282e (patch)
tree841ab9ff2ebf92ad57bc9189eefc7448260577d1 /qpid/cpp/tests/client_test.cpp
parent4ee7e8cbd677bd2ddf3f49d535a547e99c0aa150 (diff)
downloadqpid-python-9ecd69ebc88fb5d82a693e51eef0475c1a6b282e.tar.gz
Fix for the most disruptive items in QPID-243.
* All #include lines now use '""' rather than '<>' where appropriate. * #include lines within the qpid project use relative includes so that the same path will work in /usr/include when installed as part of the client libraries. * All the source code has now been rearranged to be under src in a directory analogous to the namespace of the classes in it. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@524769 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/tests/client_test.cpp')
-rw-r--r--qpid/cpp/tests/client_test.cpp138
1 files changed, 0 insertions, 138 deletions
diff --git a/qpid/cpp/tests/client_test.cpp b/qpid/cpp/tests/client_test.cpp
deleted file mode 100644
index 92952c69b1..0000000000
--- a/qpid/cpp/tests/client_test.cpp
+++ /dev/null
@@ -1,138 +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.
- *
- */
-
-/**
- * This file provides a simple test (and example) of basic
- * functionality including declaring an exchange and a queue, binding
- * these together, publishing a message and receiving that message
- * asynchronously.
- */
-
-#include <iostream>
-
-#include <QpidError.h>
-#include <ClientChannel.h>
-#include <Connection.h>
-#include <ClientMessage.h>
-#include <MessageListener.h>
-#include <sys/Monitor.h>
-#include <FieldTable.h>
-
-using namespace qpid::client;
-using namespace qpid::sys;
-using std::string;
-
-bool verbose = false;
-
-/**
- * A simple message listener implementation that prints out the
- * message content then notifies a montitor allowing the test to
- * complete.
- */
-class SimpleListener : public virtual MessageListener{
- Monitor* monitor;
-
-public:
- inline SimpleListener(Monitor* _monitor) : monitor(_monitor){}
-
- inline virtual void received(Message& msg){
- if (verbose)
- std::cout << "Received message " << msg.getData() << std::endl;
- monitor->notify();
- }
-};
-
-int main(int argc, char**)
-{
- verbose = argc > 1;
- try {
- //Use a custom exchange
- Exchange exchange("MyExchange", Exchange::TOPIC_EXCHANGE);
- //Use a named, temporary queue
- Queue queue("MyQueue", true);
-
-
- Connection con(verbose);
- string host("localhost");
- con.open(host, 5672, "guest", "guest", "/test");
- if (verbose)
- std::cout << "Opened connection." << std::endl;
-
- //Create and open a channel on the connection through which
- //most functionality is exposed
- Channel channel;
- con.openChannel(channel);
- if (verbose) std::cout << "Opened channel." << std::endl;
-
- //'declare' the exchange and the queue, which will create them
- //as they don't exist
- channel.declareExchange(exchange);
- if (verbose) std::cout << "Declared exchange." << std::endl;
- channel.declareQueue(queue);
- if (verbose) std::cout << "Declared queue." << std::endl;
-
- //now bind the queue to the exchange
- qpid::framing::FieldTable args;
- channel.bind(exchange, queue, "MyTopic", args);
- if (verbose) std::cout << "Bound queue to exchange." << std::endl;
-
- //Set up a message listener to receive any messages that
- //arrive in our queue on the broker. We only expect one, and
- //as it will be received on another thread, we create a
- //montior to use to notify the main thread when that message
- //is received.
- Monitor monitor;
- SimpleListener listener(&monitor);
- string tag("MyTag");
- channel.consume(queue, tag, &listener);
- if (verbose) std::cout << "Registered consumer." << std::endl;
-
- //we need to enable the message dispatching for this channel
- //and we want that to occur on another thread so we call
- //start().
- channel.start();
-
- //Now we create and publish a message to our exchange with a
- //routing key that will cause it to be routed to our queue
- Message msg;
- string data("MyMessage");
- msg.setData(data);
- channel.publish(msg, exchange, "MyTopic");
- if (verbose) std::cout << "Published message: " << data << std::endl;
-
- {
- Monitor::ScopedLock l(monitor);
- //now we wait until we receive notification that the
- //message was received
- monitor.wait();
- }
-
- //close the channel & connection
- channel.close();
- if (verbose) std::cout << "Closed channel." << std::endl;
- con.close();
- if (verbose) std::cout << "Closed connection." << std::endl;
- return 0;
- } catch(const std::exception& e) {
- std::cout << e.what() << std::endl;
- }
- return 1;
-}