func main() { done := make(chan bool) //create active/standby servant activeServant := NewServant("servant1", Active, done) standbyServant := NewServant("servant2", Standby, done) //connect servants by connecting their proxies configured with filters filter := &ServantFilter{"/Sys/Ctrl/Heartbeat"} //only allow heartbeats between active/standby proxy1 := router.NewProxy(activeServant.Rot, "", filter, nil) proxy2 := router.NewProxy(standbyServant.Rot, "", filter, nil) proxy1.Connect(proxy2) //wait for servants to exit <-done <-done }
func (s *Servant) Run(done chan bool) { addr := ServantAddr1 if s.role == Standby { addr = ServantAddr2 } os.Remove(addr) l, _ := net.Listen("unix", addr) //keep accepting client conn and connect local router to it for { conn, err := l.Accept() if err != nil { fmt.Println(err) continue } fmt.Println(s.name, "connect one client") //use flow control proxy := router.NewProxy(s.Rot, "", nil, nil) err = proxy.ConnectRemote(conn, router.GobMarshaling, router.FlowControl) if err != nil { fmt.Println(err) continue } } //in fact never reach here s.Rot.Close() l.Close() done <- true }