RIght ZeroMQ topology

大兔子大兔子 提交于 2019-12-07 17:23:09

问题


I need to write an Order Manager that routes client (stock, FX, whatever) orders to the proper exchange. The clients want to send orders, but know nothing about FIX or other proprietary protocols, only an internal (normalized) format for sending orders. I have applications (servers) that each connect through FIX/Binary/etc connections to each FIX/etc provider. I would like a broker program in between the clients and the servers that take the normalized order and turn it into a proper format to a given FIX/etc provider, and take messages from the servers and turn it back to a normalized format for the clients. It is ok for the clients to specify a route, but it is up to a broker program in between the clients and the servers to communicate messages about that order back and forth between clients and servers. So somehow the output [fills, partial fills, errors, etc] from the server has to be routed back to the right client.

I have studied the ZMQ topologies, and REQ->ROUTER->DEALER doesn't work [the code works - I mean it is the wrong topology] since the servers are not identical.

//This topology doesn't work because the servers are not identical
#include "zhelpers.hpp"

int main (int argc, char *argv[])
{
    // Prepare our context and sockets
    zmq::context_t context(1);
    zmq::socket_t frontend (context, ZMQ_ROUTER);
    zmq::socket_t backend (context, ZMQ_DEALER); // ZMQ_ROUTER here? Can't get it to work

    frontend.bind("tcp://*:5559");
    backend.bind("tcp://*:5560");

    // Start built-in device
    zmq::device (ZMQ_QUEUE, frontend, backend);


    return 0;
}

I thought that maybe a ROUTER->ROUTER topology instead is correct, but I can't get the code to work - the clients send orders but never get responses back so I must be doing something wrong. I thought that using ZMQ_IDENTITY is the correct thing to do, but not only can I also not get this to work, but it seems as if ZMQ is moving away from ZMQ_IDENTITY?

Can someone give a simple example of three ZMQ programs [not in separate threads, three separate processes] that show the correct way to do this?


回答1:


Look at the MajorDomo example in the Guide: http://zguide.zeromq.org/page:all#toc71

You'd use a worker pool per exchange.




回答2:


Responding to:

ROUTER->ROUTER topology instead is correct, but I can't get the code to work

My understanding is that ZMQ Sockets comes in Pairs to enable a certain pattern.

  1. PAIR
  2. REQ/REP
  3. PUB/SUB
  4. PUSH/PULL

Only PAIR socket type can talk to another socket of type PAIR and behaves similar to your normal socket.

For all other socket types, there is a complimentary socket type for communication. For example REQ socket type can only talk to REP socket type. REQ Socket type can not talk to REQ socket type.

My understanding is that in ROUTER/DEALER, ROUTER can talk to DEALER but ROUTER can not talk to ROUTER socket type.

My understanding could be wrong but from the examples this is what I have understood so far.



来源:https://stackoverflow.com/questions/11179061/right-zeromq-topology

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