2017-12-09 4 views
0

현재 하나의 큐 "devQueue"로 메시지를 보낼 수 있습니다. 메시지가 "devQueue"에 도착하면 "localQueue"로 보내야합니다. 나는이 구현이 어렵다는 것을 알고있다. "local1"클래스에서 "local_send"라는 다른 클래스를 호출하여 "localQueue"(아래 코드에서와 같이)이지만 다른 행운과 연결할 수 있습니다. 유용한 양성자 함수가 있습니까? 아니면 v_message() 함수에서 "class1"클래스의 on_connection_open()에서 참조 변수를 사용할 수 있습니까? 이 방향에서 어떤 도움이나 아이디어라도 크게 감사 할 것입니다.Qpid Proton : 두 목적지에 메시지 보내기

현재 코드가 "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); 
    } 
} 
}; 

답변

1

메시지를 보낼 채널을 만들려면 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 (동일한 핸들러에서)을 사용하여 크레디트가있을 때 보낼 수 있습니다.

+0

감사합니다 저스틴! 이것은 매우 도움이되었고 효과적이었습니다. 리팩토링하는 동안 메시지 구성에 대한 통찰력이 필요합니다. 이 게시물을 통해 확장하는 방법을 알아낼 수 없으므로 다른 게시물에 게시됩니다. – Mooni

관련 문제