예제 #1
0
파일: broker.go 프로젝트: alxzh/two-queues
func Serve(quiet bool) {

	context, _ := zmq.NewContext()
	receiver, _ := context.NewSocket(zmq.PULL)
	receiver.Bind("tcp://*:5562")
	sender, _ := context.NewSocket(zmq.PUB)
	sender.Bind("tcp://*:5561")

	last := time.Now()
	messages := 0
	for {
		message, err := receiver.Recv(0)
		if err != nil {
			fmt.Println(err)
		}
		sender.Send(message, 0)
		if !quiet {
			messages += 1
			now := time.Now()
			if now.Sub(last).Seconds() > 1 {
				println(messages, "msg/sec")
				last = now
				messages = 0
			}
		}
	}

}
예제 #2
0
파일: clients.go 프로젝트: alxzh/two-queues
func NewZMQClient(host string) (*ZMQClient, error) {
	var err error
	var context *zmq.Context
	context, err = zmq.NewContext()
	if err != nil {
		return nil, err
	}
	var pub *zmq.Socket
	pub, err = context.NewSocket(zmq.PUSH)
	if err != nil {
		return nil, err
	}
	pub.Connect(fmt.Sprintf("tcp://%s:%d", host, 5562))
	var sub *zmq.Socket
	sub, err = context.NewSocket(zmq.SUB)
	if err != nil {
		return nil, err
	}
	sub.Connect(fmt.Sprintf("tcp://%s:%d", host, 5561))
	return &ZMQClient{context, pub, sub}, nil
}