void receivedFromSource(Message& message) { QPID_LOG(debug, "transfering " << (transfered+1) << " of " << expected); message.getDeliveryProperties().setRoutingKey(destination); async(sourceSubscription.getSession()).messageTransfer(arg::content=message); if (++transfered == expected) { QPID_LOG(info, "completed job: " << transfered << " messages shifted from " << source << " to " << destination); sourceSubscription.accept(sourceSubscription.getUnaccepted()); sourceSubscription.getSession().txCommit(); sourceSubscription.cancel(); //grant credit to allow broker to send us another control message controlSubscription.grantMessageCredit(1); } }
void run() { // Publisher try { string data; size_t offset(0); if (opts.uniqueData) { offset = 5; data += "data:";//marker (requested for latency testing tool scripts) data += string(sizeof(size_t), 'X');//space for seq no data += session.getId().str(); if (opts.size > data.size()) { data += string(opts.size - data.size(), 'X'); } else if(opts.size < data.size()) { cout << "WARNING: Increased --size to " << data.size() << " to honour --unique-data" << endl; } } else { size_t msgSize=max(opts.size, sizeof(size_t)); data = string(msgSize, 'X'); } Message msg(data, routingKey); if (opts.durable) msg.getDeliveryProperties().setDeliveryMode(framing::PERSISTENT); if (opts.headers) { for (size_t i = 0; i < opts.headers; ++i) { std::stringstream h; h << "hdr" << i; msg.getMessageProperties().getApplicationHeaders().setString(h.str(), h.str()); } } if (opts.txPub){ session.txSelect(); } SubscriptionManager subs(session); LocalQueue lq; subs.setFlowControl(0, SubscriptionManager::UNLIMITED, false); Subscription cs = subs.subscribe(lq, fqn("pub_start")); for (size_t j = 0; j < opts.iterations; ++j) { cs.grantMessageCredit(1); expect(lq.pop().getData(), "start"); AbsTime start=now(); for (size_t i=0; i<opts.count; i++) { // Stamp the iteration into the message data, avoid // any heap allocation. const_cast<std::string&>(msg.getData()).replace(offset, sizeof(size_t), reinterpret_cast<const char*>(&i), sizeof(size_t)); if (opts.syncPub) { sync(session).messageTransfer( arg::destination=destination, arg::content=msg, arg::acceptMode=1); } else { session.messageTransfer( arg::destination=destination, arg::content=msg, arg::acceptMode=1); } if (opts.txPub && ((i+1) % opts.txPub == 0)){ if (opts.commitAsync){ session.txCommit(); } else { sync(session).txCommit(); } } if (opts.intervalPub) qpid::sys::usleep(opts.intervalPub*1000); } if (opts.confirm) session.sync(); AbsTime end=now(); double time=secs(start,end); if (time <= 0.0) { throw Exception("ERROR: Test completed in zero seconds. Try again with a larger message count."); } // Send result to controller. Message report(lexical_cast<string>(opts.count/time), fqn("pub_done")); session.messageTransfer(arg::content=report, arg::acceptMode=1); if (opts.txPub){ sync(session).txCommit(); } } session.close(); } catch (const std::exception& e) { cout << "PublishThread exception: " << e.what() << endl; } }