You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2021/04/18 21:09:54 UTC

[GitHub] [qpid-proton] DreamPearl commented on a change in pull request #309: PROTON-2370: [cpp] An accessor for the delivery tag

DreamPearl commented on a change in pull request #309:
URL: https://github.com/apache/qpid-proton/pull/309#discussion_r615454611



##########
File path: cpp/src/delivery_test.cpp
##########
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <proton/connection.hpp>
+#include <proton/connection_options.hpp>
+#include <proton/container.hpp>
+#include <proton/delivery.hpp>
+#include <proton/link.hpp>
+#include <proton/listen_handler.hpp>
+#include <proton/listener.hpp>
+#include <proton/message.hpp>
+#include <proton/message_id.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/tracker.hpp>
+#include <proton/types.hpp>
+#include <proton/value.hpp>
+
+#include "proton/error_condition.hpp"
+#include "proton/internal/pn_unique_ptr.hpp"
+#include "proton/receiver_options.hpp"
+#include "proton/transport.hpp"
+#include "proton/work_queue.hpp"
+#include "test_bits.hpp"
+
+#include <iostream>
+#include <map>
+
+#include <cstdio>
+#include <cstdlib>
+#include <ctime>
+#include <sstream>
+#include <string>
+
+class direct_recv : public proton::messaging_handler {
+  private:
+    class listener_ready_handler : public proton::listen_handler {
+        void on_open(proton::listener &l) PN_CPP_OVERRIDE {
+            std::cout << "listening on " << l.port() << std::endl;
+        }
+    };
+
+    std::string url;
+    proton::listener listener;
+    listener_ready_handler listen_handler;
+
+  public:
+    direct_recv(const std::string &s) : url(s) {}
+
+    void on_container_start(proton::container &c) PN_CPP_OVERRIDE {
+        listener = c.listen(url, listen_handler);
+    }
+
+    void on_message(proton::delivery &d, proton::message &msg) PN_CPP_OVERRIDE {
+
+        std::cout << msg.body() << std::endl;
+        d.receiver().close();
+        d.connection().close();
+        listener.stop();
+    }
+};
+
+class simple_send : public proton::messaging_handler {
+  private:
+    std::string url;
+    proton::sender sender;
+
+  public:
+    simple_send(const std::string &s) : url(s) {}
+
+    void on_container_start(proton::container &c) PN_CPP_OVERRIDE {
+        proton::connection_options co;
+        sender = c.open_sender(url, co);
+    }
+
+    void on_sendable(proton::sender &s) PN_CPP_OVERRIDE {
+        proton::message msg;
+        std::string m = "testing";
+        msg.body(m);
+        s.send(msg);
+    }
+};
+
+int test_delivery() {
+    std::string address("127.0.0.1:5672/examples");
+    direct_recv recv(address);
+    proton::container(recv).run();

Review comment:
       I tried using the first approach as you suggested i.e. to start the receiver in a new thread. In addition, I had to use `condition_variable` just to make sure that the listener thread is ready before the sender sends the message. It seems to be working fine now. Thanks!!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org