This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new f99db14  ARTEMIS-2249 - update cpp example to use correct client libs
     new 9e22a04  This closes #2546
f99db14 is described below

commit f99db14c3a8d6666e8fd397b83e1c36913817fc3
Author: andytaylor <[email protected]>
AuthorDate: Fri Feb 8 13:24:16 2019 +0000

    ARTEMIS-2249 - update cpp example to use correct client libs
    
    https://issues.apache.org/jira/browse/ARTEMIS-2249
---
 examples/protocols/amqp/proton-cpp/compile.sh      |  2 +-
 examples/protocols/amqp/proton-cpp/readme.md       |  2 +-
 .../amqp/proton-cpp/src/main/cpp/fake_cpp11.hpp    | 34 ++++++++
 .../amqp/proton-cpp/src/main/cpp/hello.cpp         | 92 ++++++++++------------
 4 files changed, 78 insertions(+), 52 deletions(-)

diff --git a/examples/protocols/amqp/proton-cpp/compile.sh 
b/examples/protocols/amqp/proton-cpp/compile.sh
index cc16a27..b4de2b4 100755
--- a/examples/protocols/amqp/proton-cpp/compile.sh
+++ b/examples/protocols/amqp/proton-cpp/compile.sh
@@ -15,4 +15,4 @@
 # specific language governing permissions and limitations
 # under the License.
 # This requires g++ and qpid-cpp-client-devel
-g++ src/main/cpp/hello.cpp  -o hello -l qpidmessaging -l qpidtypes
+g++ src/main/cpp/hello.cpp  -o hello -l qpid-proton-cpp -l qpidtypes
diff --git a/examples/protocols/amqp/proton-cpp/readme.md 
b/examples/protocols/amqp/proton-cpp/readme.md
index 2acf171..4b8a056 100644
--- a/examples/protocols/amqp/proton-cpp/readme.md
+++ b/examples/protocols/amqp/proton-cpp/readme.md
@@ -9,7 +9,7 @@ To run this example simply run the command **mvn verify 
-Pexample**, execute the
     # first make sure you have the dependencies you need to compile and run 
the client
     # You will have to adapt this step according to your platform. Consult the 
[qpid docs](http://qpid.apache.org/releases/qpid-0.30/programming/book/) for 
more information.
     # There is a list of [packages](http://qpid.apache.org/packages.html) you 
can install as well.
-    [proton-cpp]$ sudo yum install qpid-cpp-client-devel
+    [proton-cpp]$ sudo yum install qpid-proton-cpp-devel qpid-proton-cpp-docs
 
     # on a first window
     [proton-cpp]$ mvn verify -Pexample
diff --git a/examples/protocols/amqp/proton-cpp/src/main/cpp/fake_cpp11.hpp 
b/examples/protocols/amqp/proton-cpp/src/main/cpp/fake_cpp11.hpp
new file mode 100644
index 0000000..693a934
--- /dev/null
+++ b/examples/protocols/amqp/proton-cpp/src/main/cpp/fake_cpp11.hpp
@@ -0,0 +1,34 @@
+#ifndef FAKE_CPP11_HPP
+#define FAKE_CPP11_HPP
+
+/*
+ * 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.
+ */
+
+/// These definitions allow us to use some new C++11 features in previous 
compilers
+///
+/// It is strongly recommended not to copy this - just use C++11/C++14 instead!
+
+#if __cplusplus < 201103L
+#define OVERRIDE
+#else
+#define OVERRIDE override
+#endif
+
+
+#endif // FAKE_CPP11_HPP
\ No newline at end of file
diff --git a/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp 
b/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
index bfe18ff..c1abd5b 100644
--- a/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
+++ b/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
@@ -7,9 +7,9 @@
  * 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
@@ -18,63 +18,55 @@
  * under the License.
  *
  */
-
-
-// Step 2. Make the proper C++ imports
-#include <qpid/messaging/Connection.h>
-#include <qpid/messaging/Message.h>
-#include <qpid/messaging/Receiver.h>
-#include <qpid/messaging/Sender.h>
-#include <qpid/messaging/Session.h>
+#include <proton/connection.hpp>
+#include <proton/container.hpp>
+#include <proton/delivery.hpp>
+#include <proton/message.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/tracker.hpp>
 
 #include <iostream>
 
-using namespace qpid::messaging;
-
-int main(int argc, char** argv) {
-    std::string broker = argc > 1 ? argv[1] : "localhost:61616";
-    std::string address = argc > 2 ? argv[2] : "exampleQueue";
-
-    // Connection options documented at 
http://qpid.apache.org/releases/qpid-0.30/programming/book/connections.html#connection-options
-    std::string connectionOptions = argc > 3 ? argv[3] : "{protocol:amqp1.0}";
-
-    try {
-         // Step 3. Create an amqp qpid 1.0 connection
-        Connection connection(broker, connectionOptions);
-        connection.open();
-
-         // Step 4. Create a session
-        Session session = connection.createSession();
-
-         // Step 5. Create a sender
-        Sender sender = session.createSender(address);
+#include "fake_cpp11.hpp"
 
-        //create a receiver
-        Receiver receiver = session.createReceiver(address);
+class hello_world : public proton::messaging_handler {
+    std::string conn_url_;
+    std::string addr_;
 
+  public:
+    hello_world(const std::string& u, const std::string& a) :
+        conn_url_(u), addr_(a) {}
 
-        for (int i = 0; i < 10; i++) {
-            Message message;
-            message.getContentObject() = "Hello world!";
-
-            message.getContentObject().setEncoding("utf8");
-            message.setContentType("text/plain");
+    void on_container_start(proton::container& c) OVERRIDE {
+        c.connect(conn_url_);
+    }
 
-            sender.send(message);
+    void on_connection_open(proton::connection& c) OVERRIDE {
+        c.open_receiver(addr_);
+        c.open_sender(addr_);
+    }
 
-            // receive the simple message
-            message = receiver.fetch(Duration::SECOND * 1);
-            std::cout << "Received a message with this following content \"" 
<< message.getContent() << "\"" << std::endl;
+    void on_sendable(proton::sender &s) OVERRIDE {
+        proton::message m("Hello World!");
+        s.send(m);
+        s.close();
+    }
 
-            // acknowledge the message
-            session.acknowledge();
-        }
+    void on_message(proton::delivery &d, proton::message &m) OVERRIDE {
+        std::cout << m.body() << std::endl;
+        d.connection().close();
+    }
+};
 
-        // close the connection
-        connection.close();
+int main(int argc, char **argv) {
+    try {
+        std::string conn_url = argc > 1 ? argv[1] : "//127.0.0.1:5672";
+        std::string addr = argc > 2 ? argv[2] : "exampleQueue";
+        hello_world hw(conn_url, addr);
+        proton::container(hw).run();
         return 0;
-    } catch(const std::exception& error) {
-        std::cerr << error.what() << std::endl;
-        return 1;
+    } catch (const std::exception& e) {
+        std::cerr << e.what() << std::endl;
     }
-}
+    return 1;
+}
\ No newline at end of file

Reply via email to