예제 #1
0
func BrokerTask() {
	//  Prepare our sockets
	frontend, _ := zmq.NewSocket(zmq.DEALER)
	frontend.Bind("tcp://*:5555")
	backend, _ := zmq.NewSocket(zmq.DEALER)
	backend.Bind("tcp://*:5556")
	zmq.Proxy(frontend, backend, nil)
}
예제 #2
0
func main() {
	//  This is where the weather server sits
	frontend, _ := zmq.NewSocket(zmq.XSUB)
	defer frontend.Close()
	frontend.Connect("tcp://192.168.55.210:5556")

	//  This is our public endpoint for subscribers
	backend, _ := zmq.NewSocket(zmq.XPUB)
	defer backend.Close()
	backend.Bind("tcp://10.1.1.0:8100")

	//  Run the proxy until the user interrupts us
	err := zmq.Proxy(frontend, backend, nil)
	log.Fatalln("Proxy interrupted:", err)
}
예제 #3
0
func main() {
	//  Start child threads
	go publisher_thread()
	go subscriber_thread()
	go listener_thread()

	time.Sleep(100 * time.Millisecond)

	subscriber, _ := zmq.NewSocket(zmq.XSUB)
	subscriber.Connect("tcp://localhost:6000")
	publisher, _ := zmq.NewSocket(zmq.XPUB)
	publisher.Bind("tcp://*:6001")
	listener, _ := zmq.NewSocket(zmq.PAIR)
	listener.Connect("inproc://pipe")
	zmq.Proxy(subscriber, publisher, listener)

	fmt.Println("interrupted")
}
예제 #4
0
func main() {
	//  Socket to talk to clients
	clients, _ := zmq.NewSocket(zmq.ROUTER)
	defer clients.Close()
	clients.Bind("tcp://*:5555")

	//  Socket to talk to workers
	workers, _ := zmq.NewSocket(zmq.DEALER)
	defer workers.Close()
	workers.Bind("inproc://workers")

	//  Launch pool of worker goroutines
	for thread_nbr := 0; thread_nbr < 5; thread_nbr++ {
		go worker_routine()
	}
	//  Connect work threads to client threads via a queue proxy
	err := zmq.Proxy(clients, workers, nil)
	log.Fatalln("Proxy interrupted:", err)
}
예제 #5
0
func server_task() {

	//  Frontend socket talks to clients over TCP
	frontend, _ := zmq.NewSocket(zmq.ROUTER)
	defer frontend.Close()
	frontend.Bind("tcp://*:5570")

	//  Backend socket talks to workers over inproc
	backend, _ := zmq.NewSocket(zmq.DEALER)
	defer backend.Close()
	backend.Bind("inproc://backend")

	//  Launch pool of worker threads, precise number is not critical
	for i := 0; i < 5; i++ {
		go server_worker()
	}

	//  Connect backend to frontend via a proxy
	err := zmq.Proxy(frontend, backend, nil)
	log.Fatalln("Proxy interrupted:", err)
}
예제 #6
0
func main() {
	var err error

	//  Socket facing clients
	frontend, _ := zmq.NewSocket(zmq.ROUTER)
	defer frontend.Close()
	err = frontend.Bind("tcp://*:5559")
	if err != nil {
		log.Fatalln("Binding frontend:", err)
	}

	//  Socket facing services
	backend, _ := zmq.NewSocket(zmq.DEALER)
	defer backend.Close()
	err = backend.Bind("tcp://*:5560")
	if err != nil {
		log.Fatalln("Binding backend:", err)
	}

	//  Start the proxy
	err = zmq.Proxy(frontend, backend, nil)
	log.Fatalln("Proxy interrupted:", err)
}