Я работаю с RabbiMQ (RPC) и хочу вернуть значение из лямбда-функции. Я вызываю эту функцию из main.cpp, но возвращаемое значение не соответствует ожидаемому (значение внутри лямбда-функции соответствует ожидаемому). Каков правильный синтаксис для этого?
Мой код:
bool RabbitMqHandler::sendResultToUserCountService(analyze_result result, Camera *cam)
{
std:: string queueName = "userCountServiceReceiveRPC" + std::to_string(cam->getUserGroupId());
const std::string correlation("2");
SimplePocoHandler handler("localhost", 5672);
AMQP::Connection connection(&handler,
AMQP::Login("localhost","123456!"),"/");
bool isExist;
AMQP::Channel channel(&connection);
AMQP::QueueCallback callback = [&](const std::string &name,
int msgcount,
int consumercount)
{
ProtobufLPR::CarResult carResult;
carResult.set_licensenumber(result.LicenseNumber);
carResult.set_analyzetime(result.Date);
std::string buf;
carResult.SerializeToString(&buf);
AMQP::Envelope env(buf);
env.setCorrelationID(correlation);
env.setReplyTo(name);
channel.publish("", queueName, env);
std::cout << "Requesting " << result.LicenseNumber << std::endl;
};
channel.declareQueue(AMQP::exclusive).onSuccess(callback);
auto receiveCallback = [&](const AMQP::Message &message,
uint64_t deliveryTag,
bool redelivered) ->bool
{
if(message.correlationID() != correlation)
return 1;
std::cout<<"Got " << message.message() <<std::endl;
handler.quit();
istringstream(message.message()) >> isExist;
return isExist;
};
channel.consume("", AMQP::noack).onReceived(receiveCallback);
handler.loop();
}