Qpid Proton:向两个目的地发送消息
Qpid Proton: sending messages to two destinations
目前,我可以将消息发送到单个队列 "devQueue"。当消息到达 "devQueue" 时,它也需要发送到 "localQueue"。我发现这个实施具有挑战性。我尝试从 "class1" class 调用不同的 class "local_send" 以便我可以连接到另一个目的地 "localQueue" (如下面的代码所示)但没有运气。是否有任何有用的质子函数,或者我可以在 v_message() 函数中的 "class1" class 中使用 on_connection_open() 中的参考变量?非常感谢这方面的任何帮助或想法。
目前代码没有进入 "local_send" class,因此消息没有被发送到 "localQueue"。
class class1 : public proton::messaging_handler {
std::string url;
std::string devQueue;
std::string localQueue;
std::vector<proton::message> msgVector;
local_send snd;
std::vector<proton::message> msgV;
public:
class1(const std::string& u, const std::string& devQueue, const std::string& localQueue) :
url(u), devQueue(devQueue), localQueue(localQueue), snd(msgVector, localQueue) {}
void on_container_start(proton::container& c) override {
c.connect(url);
}
void on_connection_open(proton::connection& c) override {
c.open_receiver(devQueue);
}
void on_message(proton::delivery &d, proton::message &msg) override {
msgV.push_back(msg);
// Here, the messages are checked if they have a valid format or not and v_message() is called
}
void v_message(const pack& msg){
this->msgVector.push_back(msg);
//I need to send the message to localQueue and hence we are running another class from here (but that is not working :( )
local_send snd(msgVector, localQueue);
proton::container(snd).run();
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
// Do I even need this class to send message to another destination?
class local_send : public proton::messaging_handler {
std::string localQueue;
std::vector<proton::message> msgVector;
public:
local_send(std::vector<proton::message> msgVector, const std::string& localQueue) :
msgVector(msgVector), localQueue(localQueue) {}
void on_connection_open(proton::connection& c) override {
c.open_receiver(localQueue);
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
您需要调用open_sender创建一个发送消息的通道。您可以在一个处理程序中完成这一切。伪代码:
proton::sender snd;
on_connection_open(conn) {
conn.open_receiver("queue1");
snd = conn.open_sender("queue2");
}
on_message(dlv, msg) {
// Relay message from queue1 to queue2
snd.send(msg);
}
此代码段未使用 on_sendable。发送在库中缓冲。如果您愿意,您可以像在代码中所做的那样使用消息向量,并使用 on_sendable(在同一处理程序中)在有信用时发送。
目前,我可以将消息发送到单个队列 "devQueue"。当消息到达 "devQueue" 时,它也需要发送到 "localQueue"。我发现这个实施具有挑战性。我尝试从 "class1" class 调用不同的 class "local_send" 以便我可以连接到另一个目的地 "localQueue" (如下面的代码所示)但没有运气。是否有任何有用的质子函数,或者我可以在 v_message() 函数中的 "class1" class 中使用 on_connection_open() 中的参考变量?非常感谢这方面的任何帮助或想法。
目前代码没有进入 "local_send" class,因此消息没有被发送到 "localQueue"。
class class1 : public proton::messaging_handler {
std::string url;
std::string devQueue;
std::string localQueue;
std::vector<proton::message> msgVector;
local_send snd;
std::vector<proton::message> msgV;
public:
class1(const std::string& u, const std::string& devQueue, const std::string& localQueue) :
url(u), devQueue(devQueue), localQueue(localQueue), snd(msgVector, localQueue) {}
void on_container_start(proton::container& c) override {
c.connect(url);
}
void on_connection_open(proton::connection& c) override {
c.open_receiver(devQueue);
}
void on_message(proton::delivery &d, proton::message &msg) override {
msgV.push_back(msg);
// Here, the messages are checked if they have a valid format or not and v_message() is called
}
void v_message(const pack& msg){
this->msgVector.push_back(msg);
//I need to send the message to localQueue and hence we are running another class from here (but that is not working :( )
local_send snd(msgVector, localQueue);
proton::container(snd).run();
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
// Do I even need this class to send message to another destination?
class local_send : public proton::messaging_handler {
std::string localQueue;
std::vector<proton::message> msgVector;
public:
local_send(std::vector<proton::message> msgVector, const std::string& localQueue) :
msgVector(msgVector), localQueue(localQueue) {}
void on_connection_open(proton::connection& c) override {
c.open_receiver(localQueue);
}
void on_sendable(proton::sender &s) override {
for(auto msg: msgVector){
s.send(msg);
}
}
};
您需要调用open_sender创建一个发送消息的通道。您可以在一个处理程序中完成这一切。伪代码:
proton::sender snd;
on_connection_open(conn) {
conn.open_receiver("queue1");
snd = conn.open_sender("queue2");
}
on_message(dlv, msg) {
// Relay message from queue1 to queue2
snd.send(msg);
}
此代码段未使用 on_sendable。发送在库中缓冲。如果您愿意,您可以像在代码中所做的那样使用消息向量,并使用 on_sendable(在同一处理程序中)在有信用时发送。