本文整理汇总了C++中Subscription::grantMessageCredit方法的典型用法代码示例。如果您正苦于以下问题:C++ Subscription::grantMessageCredit方法的具体用法?C++ Subscription::grantMessageCredit怎么用?C++ Subscription::grantMessageCredit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription::grantMessageCredit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receivedFromSource
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);
}
}
示例2: run
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;
}
}