summaryrefslogtreecommitdiff
path: root/cpp/examples/messaging
diff options
context:
space:
mode:
authorJonathan Robie <jonathan@apache.org>2010-04-15 22:14:59 +0000
committerJonathan Robie <jonathan@apache.org>2010-04-15 22:14:59 +0000
commit21ad028dcbd65ee52f8b00c1d8c8ccba7e3e321a (patch)
tree2f5be2284955cb8d3b3b08db12e4b1f1c2deeeac /cpp/examples/messaging
parentaa2267746692dc5247a42fb9c884b6863f63cd2b (diff)
downloadqpid-python-21ad028dcbd65ee52f8b00c1d8c8ccba7e3e321a.tar.gz
Applied Gordon's patch - much simpler now.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@934624 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/examples/messaging')
-rw-r--r--cpp/examples/messaging/hello_world.cpp60
1 files changed, 23 insertions, 37 deletions
diff --git a/cpp/examples/messaging/hello_world.cpp b/cpp/examples/messaging/hello_world.cpp
index 360a22d1c2..9c06964a66 100644
--- a/cpp/examples/messaging/hello_world.cpp
+++ b/cpp/examples/messaging/hello_world.cpp
@@ -5,45 +5,31 @@
#include <qpid/messaging/Session.h>
#include <iostream>
-#include <sstream>
using namespace qpid::messaging;
-int main() {
-
- Connection connection("localhost:5672");
- try {
- connection.open();
- Session session = connection.createSession();
-
- std::string address = "message_queue";
-
- Sender sender = session.createSender(address);
-
- for (int i=0; i<5; i++) {
- std::stringstream content;
- content << "Message " << i;
- std::cout << "Sending " << content.str() << std::endl;
- sender.send(Message(content.str()));
+int main(int argc, char** argv) {
+ std::string broker = argc > 1 ? argv[1] : "localhost:5672";
+ std::string address = argc > 2 ? argv[2] : "amq.topic";
+ Connection connection(broker);
+ try {
+ connection.open();
+ Session session = connection.createSession();
+
+ Receiver receiver = session.createReceiver(address);
+ Sender sender = session.createSender(address);
+
+ sender.send(Message("Hello world!"));
+
+ Message message = receiver.fetch(Duration::SECOND * 1);
+ std::cout << message.getContent() << std::endl;
+ session.acknowledge();
+
+ connection.close();
+ return 0;
+ } catch(const std::exception& error) {
+ std::cerr << error.what() << std::endl;
+ connection.close();
+ return 1;
}
- sender.close();
-
- Receiver receiver = session.createReceiver(address);
-
- Message message;
- Duration timeout(1000); /* in milliseconds */
- while (receiver.fetch(message, timeout)) {
- std::cout << "Received " << message.getContent() << std::endl;
- session.acknowledge();
- }
-
- receiver.close();
-
- connection.close();
- return 0;
- } catch(const std::exception& error) {
- std::cerr << error.what() << std::endl;
- connection.close();
- return 1;
- }
}