2828#include < proton/messaging_handler.hpp>
2929#include < proton/sender_options.hpp>
3030#include < proton/types.hpp>
31- #include < proton/transaction_handler.hpp>
3231
3332#include < iostream>
3433#include < map>
3837#include < chrono>
3938#include < thread>
4039
41- class tx_send : public proton ::messaging_handler, proton::transaction_handler {
40+ class tx_send : public proton ::messaging_handler {
4241 private:
4342 proton::sender sender;
4443 std::string conn_url_;
@@ -65,27 +64,27 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
6564 }
6665
6766 void on_session_open (proton::session& s) override {
68- std::cout << " New session is open, declaring transaction now..." << std::endl;
69- s.transaction_declare (*this );
67+ if (!s.transaction_is_declared ()) {
68+ std::cout << " New session is open, declaring transaction now..." << std::endl;
69+ s.transaction_declare (*this );
70+ } else {
71+ std::cout << " Transaction is declared: " << s.transaction_id () << std::endl;
72+ send ();
73+ }
7074 }
7175
72- void on_transaction_declare_failed (proton::session s) override {
73- std::cout << " Transaction declarion failed " << std::endl;
76+ void on_session_error (proton::session & s) override {
77+ std::cout << " Session error: " << s. error (). what () << std::endl;
7478 s.connection ().close ();
7579 exit (-1 );
7680 }
7781
78- void on_transaction_commit_failed (proton::session s) override {
82+ void on_session_transaction_commit_failed (proton::session & s) override {
7983 std::cout << " Transaction commit failed!" << std::endl;
8084 s.connection ().close ();
8185 exit (-1 );
8286 }
8387
84- void on_transaction_declared (proton::session s) override {
85- std::cout << " Transaction is declared: " << s.transaction_id () << std::endl;
86- send ();
87- }
88-
8988 void on_sendable (proton::sender&) override {
9089 send ();
9190 }
@@ -117,7 +116,7 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
117116 }
118117 }
119118
120- void on_transaction_committed (proton::session s) override {
119+ void on_session_transaction_committed (proton::session & s) override {
121120 committed += current_batch;
122121 current_batch = 0 ;
123122 std::cout << " Transaction commited" << std::endl;
@@ -131,7 +130,7 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
131130 }
132131 }
133132
134- void on_transaction_aborted (proton::session s) override {
133+ void on_session_transaction_aborted (proton::session & s) override {
135134 std::cout << " Transaction aborted!" << std::endl;
136135 std::cout << " Re-delaring transaction now..." << std::endl;
137136 current_batch = 0 ;
0 commit comments