Pages

Queue Broker v.2 rewritten

A few days ago, I wrote a version of the Least Recently Used Queue broker based on a subclass of the standard C++ ZeroMQ socket_t class. I have just redesigned it to change the way multipart messages are managed, you can read some more about the new zmq::Socket in its specific post. Here I say something about the changes in the broker itself.

The full broker source code is on github, in any case, the changes are in the way multipart messages are managed.

For instance, we can have a look at MyDevice::receivingOnBackend():
void receivingOnBackend()
{
//    zmq::Frames input = backend_.blockingRecv(3, false);
    zmq::Frames input = backend_.blockingRecv(5, false); // workerID (, "", clientID, "", payload) // 1

    // ...
    
//    if(input.size() == 3)
    if(input.size() == 5) // 2
    {
//        zmq::Frames output(input.begin() + 1, input.end());
        zmq::Frames output(input.begin() + 2, input.end()); // 3
        frontend_.send(output);
    }
}
1. On the backend we receive a workerID and, normally, the clientID and the message payload. That means one or three "real" frames. In my original implementation, we didn't get the separators, now we do. So we get a total of one or five frames.
2. As said above, a full message now has size 5, and not anymore 3.
3. We send to the frontend the clientID and the payload, to do that we discard the first two frames, the workerID and the first separator.

No comments:

Post a Comment