func NewClient(server string, requestTimeout int) *client { context, _ := zmq.NewContext() self := &client{ server: server, context: context, timeout: 2500 * time.Millisecond, requestTimeout: time.Duration(requestTimeout) * time.Millisecond, } self.connect() return self }
func main() { context, _ := zmq.NewContext() socket, _ := context.NewSocket(zmq.REP) socket.Bind("tcp://127.0.0.1:5000") socket.Bind("tcp://127.0.0.1:6000") for { msg, _ := socket.Recv(0) println("Got", string(msg)) socket.Send(msg, 0) } }
func main() { context, _ := zmq.NewContext() socket, _ := context.NewSocket(zmq.REQ) socket.Connect("tcp://127.0.0.1:5000") socket.Connect("tcp://127.0.0.1:6000") for i := 0; i < 10; i++ { msg := fmt.Sprintf("msg %d", i) socket.Send([]byte(msg), 0) println("Sending", msg) socket.Recv(0) } }
func NewWorker(broker, service string, verbose bool) Worker { context, _ := zmq.NewContext() self := &lbWorker{ broker: broker, context: context, service: service, verbose: verbose, heartbeat: 2500 * time.Millisecond, liveness: 0, reconnect: 2500 * time.Millisecond, } self.reconnectToBroker() return self }
func NewLoadBalancer(frontendEndpoint, backendEndpoint string) *loadBalancer { context, _ := zmq.NewContext() // Define inproc socket to talk with HTTP CLient API frontend, _ := context.NewSocket(zmq.ROUTER) frontend.SetLinger(0) frontend.Bind(frontendEndpoint) // Define tcp socket to talk with Workers backend, _ := context.NewSocket(zmq.ROUTER) backend.SetLinger(0) backend.Bind(backendEndpoint) return &loadBalancer{ context: context, heartbeatAt: time.Now().Add(HEARTBEAT_INTERVAL), services: make(map[string]*lbService), frontend: frontend, backend: backend, waiting: NewList(), workers: make(map[string]*lbWorker), chains: make(map[string]lbChain), } }