В настоящее время я могу отправлять сообщения в одну очередь «devQueue». Когда сообщение поступает в «devQueue», его также необходимо отправить в «localQueue». Я нахожу эту реализацию сложной. Я попытался вызвать другой класс «local_send» из класса «class1», чтобы я мог подключиться к другому месту назначения, которое является «localQueue» (как показано в коде ниже), но безуспешно. Есть ли какая-нибудь функция протона, которая была бы полезна, или я могу использовать ссылочную переменную из on_connection_open() в классе «class1» внутри функции v_message()? Любая помощь или идея в этом направлении будет принята с благодарностью.
В настоящее время код не попадает в класс «local_send», и, следовательно, сообщения не отправляются в «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);
}
}
};