zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.79k stars 2.36k forks source link

zmq_proxy support other load balance algorithm #3443

Open jiephe opened 5 years ago

jiephe commented 5 years ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

zmq_proxy support other load balance algorithm except round-robining, for example, self-defined algorithm or other

Environment

Minimal test code / Steps to reproduce the issue

What's the actual result? (include assertion message & call stack if applicable)

What's the expected result?

sigiesec commented 5 years ago

Have you got an idea how the interface should look like to allow for a self-defined algorithm? Some callback function needs to be passed to the proxy to allow for that.

jiephe commented 5 years ago

if have some callback function that is well, at last i self-defined my own load-balance above zmq_proxy

sigiesec commented 5 years ago

Can you supply an example of how the callback function might look like? What information/parameters does it require? What would it return as a result?

jiephe commented 5 years ago

At last, i split zmq_proxy, like this: `

          auto router = fmt::format("tcp://*:{}", routerPort_);

    auto frontend = zmq_socket(context_, ZMQ_ROUTER);
    zmq_bind(frontend, router.c_str());

    auto backend = zmq_socket(context_, ZMQ_DEALER);
    zmq_bind(backend, "inproc://workers");

    zmq_proxy(frontend, backend, nullptr);

           ......
      auto front = zmq_socket(context_, ZMQ_DEALER);
    zmq_connect(front, "inproc://workers");

    auto router = fmt::format("tcp://*:{}", dealerPort_);
    auto back = zmq_socket(context_, ZMQ_ROUTER);
    zmq_bind(back, router.c_str());

    zmq_pollitem_t items[] = { { front, 0, ZMQ_POLLIN, 0 }, { back, 0, ZMQ_POLLIN, 0 } };

    while (1)
    {
        int rc = zmq_poll(items, sizeof(items) / sizeof(zmq_pollitem_t), 1000);
        if (rc < 0)
            break;

        if (rc < 1)
            continue;

        if (items[0].revents & ZMQ_POLLIN)
        {
                    }

                    if (items[1].revents & ZMQ_POLLIN)
        {
                    }
            }

` front/back server which links to zmq_proxy upload filter conditions, and when message arrive at zmq_proxy, will select a front/back server with uploaded conditions according to some rules. Maybe, callback funtions can not become my requests.