How does an RPC client also work as an event handler?

58 views
Skip to first unread message

bpr...@hotmail.com

unread,
Apr 8, 2019, 6:03:59 AM4/8/19
to Serf
Hello,

From the docs, I've understood that the RPC client can be used to send commands to the agent. It is also mentioned that it can serve as an IPC mechanism to behave as an event handler
 Additionally, it can be used as a fast IPC mechanism to allow applications to receive events immediately instead of using the fork/exec model of event handlers.

I'm not able to wrap my head around this - I get that the RPC will allow me to control the Serf agent programatically, and I understand the aspect of sending commands (The command is wrapped up in MsgPack and sent to the RPC listener port on the agent)

I'm not able to figure out how to receive events and queries, and invoke event handlers using the RPC (Where do I get the incoming MsgPack event from, and how do I parse it to find out what event it is?)

I've not been able to find any implementations/examples of the second aspect. The comments in the ipc.go file seem to describe it, but again, it's not all that helpful.

Can anyone shine a light on this?

Thanks

 

Matthias Urlichs

unread,
Apr 8, 2019, 6:13:39 AM4/8/19
to ser...@googlegroups.com
On 08.04.19 12:03, bpr...@hotmail.com wrote:
I'm not able to figure out how to receive events and queries

Short answer: You send a "stream" command and subsequently get matching events and queries until you send "stop" (or close the connection of course). https://www.serf.io/docs/agent/rpc.html#stream

You respond to queries using, surprise, a "respond" command.

Which programming language? if Python, https://github.com/smurfix/trio-serf implements all of this in a hopefully-understandable way.

-- 
-- mit freundlichen Grüßen
-- 
-- Matthias Urlichs

bpr...@hotmail.com

unread,
Apr 8, 2019, 6:33:25 AM4/8/19
to Serf
Thanks Matthias for the quick reply!

With regard to the programming language, I need to use something light, like C/C++. There is an RPC client in cpp, but it doesn't look like it's widely used. 
Would it be possible to just form MsgPack statements and send it to the RPC port, and in the same way, get MsgPack statements and unpack and parse them? (I won't be needing all the features of the RPC client)
Reply all
Reply to author
Forward
0 new messages