@@ -49,7 +49,7 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
4949 int confirmed = 0 ;
5050
5151 proton::session session;
52- proton::transaction transaction;
52+ // proton::transaction transaction;
5353 public:
5454 tx_send (const std::string &s, int c, int b):
5555 url (s), total(c), batch_size(b), sent(0 ) {}
@@ -65,32 +65,31 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
6565 std::cout << " [on_session_open] declare_txn ended..." << std::endl;
6666 }
6767
68- void on_transaction_declare_failed (proton::transaction ) {}
69- void on_transaction_commit_failed (proton::transaction t ) {
68+ void on_transaction_declare_failed (proton::session ) {}
69+ void on_transaction_commit_failed (proton::session s ) {
7070 std::cout << " Transaction Commit Failed" << std::endl;
71- t .connection ().close ();
71+ s .connection ().close ();
7272 exit (-1 );
7373 }
7474
75- void on_transaction_declared (proton::transaction t ) override {
76- std::cout << " [on_transaction_declared] txn called " << (&t )
75+ void on_transaction_declared (proton::session s ) override {
76+ std::cout << " [on_transaction_declared] Session: " << (&s )
7777 << std::endl;
78- std::cout << " [on_transaction_declared] txn is_empty " << (t.is_empty ())
79- << " \t " << transaction.is_empty () << std::endl;
80- transaction = t;
78+ std::cout << " [on_transaction_declared] txn is_empty " << (s.txn_is_empty ())
79+ << " \t " << std::endl;
8180
8281 send (sender);
8382 }
8483
8584 void on_sendable (proton::sender &s) override {
86- std::cout << " [OnSendable] transaction : " << &transaction
85+ std::cout << " [OnSendable] session : " << &session
8786 << std::endl;
8887 send (s);
8988 }
9089
9190 void send (proton::sender &s) {
9291 static int unique_id = 10000 ;
93- while (!transaction. is_empty () && sender.credit () &&
92+ while (!session. txn_is_empty () && sender.credit () &&
9493 (committed + current_batch) < total) {
9594 proton::message msg;
9695 std::map<std::string, int > m;
@@ -100,18 +99,17 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
10099 msg.body (m);
101100 std::cout << " ##### [example] transaction send msg: " << msg
102101 << std::endl;
103- transaction. send (sender, msg);
102+ session. txn_send (sender, msg);
104103 current_batch += 1 ;
105104 if (current_batch == batch_size)
106105 {
107106 std::cout << " >> Txn attempt commit" << std::endl;
108107 if (batch_index % 2 == 0 ) {
109- transaction. commit ();
108+ session. txn_commit ();
110109 } else {
111- transaction. abort ();
110+ session. txn_abort ();
112111 }
113-
114- transaction = proton::transaction ();
112+ // TODO: Only one transaction is permitted per session.
115113 batch_index++;
116114 }
117115 }
@@ -123,20 +121,20 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
123121 << std::endl;
124122 }
125123
126- void on_transaction_committed (proton::transaction t ) override {
124+ void on_transaction_committed (proton::session s ) override {
127125 committed += current_batch;
128126 current_batch = 0 ;
129127 std::cout<<" [OnTxnCommitted] Committed:" << committed<< std::endl;
130128 if (committed == total) {
131129 std::cout << " All messages committed" << std::endl;
132- t .connection ().close ();
130+ s .connection ().close ();
133131 }
134132 else {
135133 session.declare_transaction (*this );
136134 }
137135 }
138136
139- void on_transaction_aborted (proton::transaction t ) override {
137+ void on_transaction_aborted (proton::session s ) override {
140138 std::cout << " Meesages Aborted ....." << std::endl;
141139 current_batch = 0 ;
142140 session.declare_transaction (*this );
@@ -150,7 +148,7 @@ class tx_send : public proton::messaging_handler, proton::transaction_handler {
150148
151149int main (int argc, char **argv) {
152150 std::string address (" 127.0.0.1:5672/examples" );
153- int message_count = 6 ;
151+ int message_count = 3 ;
154152 int batch_size = 3 ;
155153 example::options opts (argc, argv);
156154
0 commit comments