dslf46995 2015-05-27 21:30
浏览 44

ZeroMQ知道请求来自哪个例程

I am trying to figure out if i have two routines calling the same zeromq socket if when the return from socket.recv() on routine1 returns.. the socket will know to return to routine1 (ditto for routine2, ... routinen).

Hence... using a messaging bus with request/response semantics, what is the best pattern to approach this in go?

If it helps.. think about the simple pirate pattern and implementing an RPC style call set in that pattern with zeromq.

Socket; //zeromq socket
//routine 1
socket.send(data) // do i need some identifier here for this routine?
socket.recv() // wait until i get a response from that send
//routine 2 
socket.send(data)
socket.recv()

so in this case i have no idea if the response from routine1 or routine2 will come back first. How can i make sure that when i get a response to socket... i can notify the correct routines' recv() function.

Thanks!

  • 写回答

1条回答 默认 最新

  • douyu4822 2015-05-27 23:13
    关注

    I don't believe a socket can be shared, concurrently, between threads using zeromq

    Likely you need to do some kind of goroutine that listens for requests, sends / receives zmq, and then replies.

    for example: (untested code)

    type Req struct {
       Data []byte 
       Reply chan []byte
    }
    
    go func() { // probably not the zmq api, but you should get the idea here
        for req := <- requests {
             socket.send(req.Data)
             req.Reply <- socket.recv() 
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog