gpt4 book ai didi

c++ - Qpid 质子 C++ - 质子::make_work

转载 作者:行者123 更新时间:2023-11-30 05:05:01 38 4
gpt4 key购买 nike

我正在尝试在 proton::connection 对象的工作队列中添加 proton::work 函数(打开一个新的发送者)。我有一个指向工作队列的指针,但我的问题是如何正确绑定(bind) open_sender 函数。

我知道这里的真正问题:函数的参数:

sender open_sender(const std::string& addr);

由于字符串是通过引用传递的,所以我必须取消引用它。我对此没意见,但如何使用质子工具做到这一点?

这是我的代码行:

proton::work w = proton::make_work( &proton::connection::open_sender, &m_connection, p_url);

注意:

  1. 当然我不会在我的项目中使用 C++11,那样太简单了问 ;) !
  2. 我当然不能改成C++11
  3. 如果您对如何在多线程程序中创建新的发件人有更好的想法,请告诉我。

最佳答案

通常您会在处理程序中使用 proton::open_sender API 来打开连接或启动容器,因此您不必在大多数情况下使用 proton::make_work个案。如果您查看 Proton C++ 示例,一个好的起点是 simple_send.cpp。

缩写代码可能如下所示:

class simple_send : public proton::messaging_handler {
private:
proton::sender sender;
const std::string url;
const std::string addr;
...
public:
simple_send(...) :
url(...),
addr(...)
{}
...
// This handler is called when the container starts
void on_container_start(proton::container &c) {
c.connect(url);
}

// This handler is called when the connection is open
void on_connection_open(proton::connection& c) {
sender = c.open_sender(addr);
}
...
}

int main() {
...
simple_send send(...);
proton::container(send).run();
...
}

Proton C++ 附带了其他示例,应该可以帮助您了解使用 Proton C++ 的其他方法。参见 https://github.com/apache/qpid-proton/tree/master/examples/cpp .

您还可以在 http://qpid.apache.org/releases/qpid-proton-0.20.0/proton/cpp/api/index.html 找到 API 文档。 (截至 2018 年 2 月的当前版本)。

关于c++ - Qpid 质子 C++ - 质子::make_work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48581346/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com