I use this as a template , except that in the same program I also have some goroutines that are working and connect to the endpoint backend, tcp: //127.0.0.1: 5560.
What I would like to do is connect it in a more efficient way, for example, ipc: //, inproc: // or even unix sockets. I tried this and it did not work. Can't channels work with ZeroMQ?
So, how do I connect different goroutines with ZeroMQ contexts, without tcp? Is there a better alternative?
Update : Code:
// Simple message queuing broker // Same as request-reply broker but using QUEUE device // // Author: Brendan Mc. // Requires: http://github.com/alecthomas/gozmq package main import ( zmq "github.com/alecthomas/gozmq" ) func startWorker() { context, _ := zmq.NewContext() defer context.Close() worker, _ := context.NewSocket(zmq.REP) //err := worker.Connect("ipc:///backend") // Tried it, but nothing //err := worker.Connect("inproc:///backend") // Tried it, but nothing err := worker.Connect("tcp://127.0.0.1:5560") // this works if err != nil { fmt.Println(err) } for { data, err := worker.Recv(0) fmt.Println(string(data)) worker.Send([]byte("I got your data"), 0) } } func main() { context, _ := zmq.NewContext() defer context.Close() // Socket facing clients frontend, _ := context.NewSocket(zmq.ROUTER) defer frontend.Close() frontend.Bind("tcp://*:5559") // Socket facing services backend, _ := context.NewSocket(zmq.DEALER) defer backend.Close() //backend.Bind("ipc:///backend") // Tried it, but nothing //backend.Bind("inproc:///backend") // Tried it, but nothing backend.Bind("tcp://*:5560") // this works for i := 0; i < 4; i++ { go startWorker() // Start workers in a separate goroutine } // Start built-in device zmq.Device(zmq.QUEUE, frontend, backend) // We never get here… }
source share