[ 
https://issues.apache.org/jira/browse/PROTON-1442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17924082#comment-17924082
 ] 

ASF GitHub Bot commented on PROTON-1442:
----------------------------------------

pematous commented on code in PR #437:
URL: https://github.com/apache/qpid-proton/pull/437#discussion_r1942997452


##########
cpp/examples/tx_recv.cpp:
##########
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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 "options.hpp"
+
+#include <proton/connection.hpp>
+#include <proton/container.hpp>
+#include <proton/message.hpp>
+#include <proton/message_id.hpp>
+#include <proton/messaging_handler.hpp>
+#include <proton/types.hpp>
+#include <proton/transaction.hpp>
+
+#include <iostream>
+#include <map>
+#include <string>
+
+#include <chrono>
+#include <thread>
+
+class tx_recv : public proton::messaging_handler, proton::transaction_handler {
+  private:
+    proton::receiver receiver; 
+    std::string url;
+    int expected;
+    int batch_size;
+    int current_batch = 0;
+    int committed = 0;
+
+    proton::session session;
+    proton::transaction transaction;
+  public:
+    tx_recv(const std::string &s, int c, int b):
+        url(s), expected(c), batch_size(b) {}
+
+    void on_container_start(proton::container &c) override {
+        receiver = c.open_receiver(url);
+    }
+
+    void on_session_open(proton::session &s) override {
+        session = s;
+        std::cout << "    [on_session_open] declare_txn started..." << 
std::endl;
+        s.declare_transaction(*this);
+        std::cout << "    [on_session_open] declare_txn ended..." << std::endl;
+    }
+
+    void on_transaction_declare_failed(proton::transaction) {}
+    void on_transaction_commit_failed(proton::transaction t) {
+        std::cout << "Transaction Commit Failed" << std::endl;
+        t.connection().close();
+        exit(-1);
+    }
+
+    void on_transaction_declared(proton::transaction t) override {
+        std::cout << "[on_transaction_declared] txn called " << (&t)
+                  << std::endl;
+        std::cout << "[on_transaction_declared] txn is_empty " << 
(t.is_empty())
+                  << "\t" << transaction.is_empty() << std::endl;
+        receiver.add_credit(batch_size); 
+        transaction = t;
+    }
+
+    void on_message(proton::delivery &d, proton::message &msg) override {
+        std::cout<<"# MESSAGE: " << msg.id() <<": "  << msg.body() << 
std::endl;
+        transaction.accept(d);
+        current_batch += 1;
+        if(current_batch == batch_size) {
+            transaction = proton::transaction(); // null

Review Comment:
   > I believe we should do rather commit here, that way it works as expected 
and the receiver is closed after expected number of messages received (with the 
current implementation it's not).
   
   above mentioned change:
   ```
   -            transaction = proton::transaction(); // null
   +           transaction.commit();
   ```
   
   works as expected (against Artemis broker) when using multicast. However, 
when a pre-defined anycast queue is used, the commit() call ends with 
segmentation fault.





> [c++] Support for transactions
> ------------------------------
>
>                 Key: PROTON-1442
>                 URL: https://issues.apache.org/jira/browse/PROTON-1442
>             Project: Qpid Proton
>          Issue Type: Improvement
>          Components: cpp-binding
>            Reporter: Radim Kubis
>            Assignee: Rakhi Kumari
>            Priority: Major
>
> Support for transactions in Qpid Proton C++.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to