ZeroMQ pattern query

自作多情 提交于 2019-12-07 23:17:09

问题


I want to implement a server/client interaction in C++ using ZeroMQ (http://zeromq.org/).

My requirement is to implement a function where if a client sends a request to the server, the server should send multiple pieces of data (in a sequence) back to the client. The client should be able to repeatedly send the request with the server replying with multiple pieces of data on each request.

ZeroMQ prescribes models like req-res, pub-sub, push-pull, but this does not support my requirement because:

1) Req-rep pattern always expects a return message i.e. it is designed as a combination of send and receive

2) pub-sub and push-pull are unidirectional

Which ZeroMQ pattern would suit my requirement, and also which protocol would be better TCP, PGM, EPGM etc....!

Thank you


回答1:


Have a look at ZMQ dealer-router architectures: http://www.zeromq.org/tutorials:dealer-and-router

You should be able to address specific clients and not have to adhere to the strict request reply type message flow.




回答2:


A fully asynchronous approach is as follows.

Client Side

Make your client use a DEALER socket. Connect to your server ROUTER.

When you send a request, send (k, v) where k is a unique (in the context of this client) request key and v is the actual request data for whatever operation you're performing.

Listen for incoming messages on the same DEALER socket. Expect a sequence of messages that look like:

  • (k, START)
  • (k, (0, 10), A[0..9])
  • (k, (10, 8), A[10..17])
  • (k, (18, 2), A[18..19])
  • (k, END)

Server Side

Make your server use a ROUTER socket. Bind it.

Listen for incoming messages of the form [sender, (k, v)].

Send back a sequence of messages that look something like:

  • [sender, (k, START)]
  • [sender, (k, (0, 10), A[0..9])]
  • [sender, (k, (10, 8), A[10..17])]
  • [sender, (k, (18, 2), A[18..19])]
  • [sender, (k, END)]

I'm using square brackets to denote ZMQ multipart messages and parentheses to denote tuples.



来源:https://stackoverflow.com/questions/16276002/zeromq-pattern-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!