[ https://issues.apache.org/jira/browse/PROTON-1442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18016820#comment-18016820 ]
ASF GitHub Bot commented on PROTON-1442: ---------------------------------------- astitcher commented on code in PR #437: URL: https://github.com/apache/qpid-proton/pull/437#discussion_r2307871160 ########## cpp/examples/tx_recv.cpp: ########## @@ -0,0 +1,132 @@ +/* + * + * 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_handler.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 conn_url_; + std::string addr_; + int expected; + int batch_size; + int current_batch = 0; + int committed = 0; + + proton::session session; + public: + tx_recv(const std::string& u, const std::string &a, int c, int b): + conn_url_(u), addr_(a), expected(c), batch_size(b) {} + + void on_container_start(proton::container &c) override { + c.connect(conn_url_); + } + + void on_connection_open(proton::connection& c) override { + c.open_session(); + } + + void on_session_open(proton::session &s) override { + s.open_sender(addr_); + session = s; + std::cout << "Session open, declare_txn" << std::endl; + s.declare_transaction(*this); + } + + void on_transaction_declare_failed(proton::session) {} + + void on_transaction_commit_failed(proton::session s) { + std::cout << "Transaction Commit Failed" << std::endl; + s.connection().close(); + exit(-1); + } + + void on_transaction_declared(proton::session s) override { + std::cout << "Transaction is declared!" << (&s) + << std::endl; + receiver.add_credit(batch_size); + } + + void on_message(proton::delivery &d, proton::message &msg) override { + std::cout<<"# MESSAGE: " << msg.id() <<": " << msg.body() << std::endl; + session.transaction_accept(d); + current_batch += 1; + if(current_batch == batch_size) { + } Review Comment: Need to commit or abort transaction here ########## cpp/include/proton/session.hpp: ########## @@ -105,14 +106,31 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>, public endp /// Get user data from this session. PN_CPP_EXTERN void* user_data() const; + PN_CPP_EXTERN void declare_transaction(proton::transaction_handler &handler, bool settle_before_discharge = false); + + PN_CPP_EXTERN bool transaction_is_empty(); + PN_CPP_EXTERN bool transaction_is_declared(); + PN_CPP_EXTERN void transaction_commit(); + PN_CPP_EXTERN void transaction_abort(); + PN_CPP_EXTERN void transaction_declare(); + PN_CPP_EXTERN void transaction_handle_outcome(proton::tracker); + PN_CPP_EXTERN void attach_txn_id(proton::tracker t); + PN_CPP_EXTERN void transaction_accept(delivery &t); + PN_CPP_EXTERN proton::connection transaction_connection() const; Review Comment: These are all internal functions and shouldn't be in the visible header file ########## cpp/examples/tx_recv.cpp: ########## @@ -0,0 +1,132 @@ +/* + * + * 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_handler.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 conn_url_; + std::string addr_; + int expected; + int batch_size; + int current_batch = 0; + int committed = 0; + + proton::session session; + public: + tx_recv(const std::string& u, const std::string &a, int c, int b): + conn_url_(u), addr_(a), expected(c), batch_size(b) {} + + void on_container_start(proton::container &c) override { + c.connect(conn_url_); + } + + void on_connection_open(proton::connection& c) override { + c.open_session(); + } + + void on_session_open(proton::session &s) override { + s.open_sender(addr_); + session = s; + std::cout << "Session open, declare_txn" << std::endl; + s.declare_transaction(*this); + } + + void on_transaction_declare_failed(proton::session) {} + + void on_transaction_commit_failed(proton::session s) { + std::cout << "Transaction Commit Failed" << std::endl; + s.connection().close(); + exit(-1); + } + + void on_transaction_declared(proton::session s) override { + std::cout << "Transaction is declared!" << (&s) + << std::endl; + receiver.add_credit(batch_size); + } + + void on_message(proton::delivery &d, proton::message &msg) override { + std::cout<<"# MESSAGE: " << msg.id() <<": " << msg.body() << std::endl; + session.transaction_accept(d); Review Comment: should just be accept now as this is already a transactioned session ########## cpp/include/proton/session.hpp: ########## @@ -105,14 +106,31 @@ PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>, public endp /// Get user data from this session. PN_CPP_EXTERN void* user_data() const; + PN_CPP_EXTERN void declare_transaction(proton::transaction_handler &handler, bool settle_before_discharge = false); Review Comment: I think this is meant to be called transaction_declare(...) once the internal function below is removed ########## cpp/include/proton/session.hpp: ########## @@ -36,6 +36,7 @@ struct pn_session_t; namespace proton { + class transaction_impl; Review Comment: transaction_impl is pirely internal and should not be in an externally visible header file > [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