Skip to content

ZMQ Message Library#91

Open
astronomerdave wants to merge 3 commits intocamera-2.0from
camera2/message-lib
Open

ZMQ Message Library#91
astronomerdave wants to merge 3 commits intocamera-2.0from
camera2/message-lib

Conversation

@astronomerdave
Copy link
Collaborator

I wrote a stand-alone ZMQ message library to replace the daemon server sockets. I've been wanting to do this for awhile because I think it will help NGPS inter-daemon communication reliability, and it makes sense (to me) that camera2 daemon uses the new method.

This is a header-only library.

It currently defines Message::Server and Message::Client which use the ROUTER-DEALER pattern.

I will eventually move my existing Common::PubSub class (currently only in NGPS) from common.h to this message.h

The Network code remains in the repo because it is needed for other things (like Archon communication, for example).

@astronomerdave
Copy link
Collaborator Author

Some of the indentation is a little funny, and some of the comments might be not quite right, but those are because I was trying to make changes only where necessary to show what little of camerad had to be changed (if I had properly indented code then a lot of lines would have been flagged as changed, obscuring the meaningful changes).

zmq::message_t routing_frame, messageid_frame, payload_frame;

// received the frames from the router
auto frame1 = router.recv(routing_frame, zmq::recv_flags::none);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendation would be to have some sort of Message class

class Message {
public:
    std::string id;
    std::string type;
    std::string payload;
};

That will allow us to shift the message from
[routing][message_id][payload] to serialized messages [routing][message_id][serialized message]

That will allow us to not have to parse for things like

ACK
DONE
ERROR something bad

So we can use type

REQUEST
ACK
DONE
ERROR
PING
PONG
PROGRESS
EVENT

and then our payload would be

{
  "id": "42",
  "type": "DONE",
  "payload": "focus set to 2.5"
}

then we go from if (payload==Message::MSG_PING) to if (msg.type == "PING")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants