Esempio n. 1
0
func main() {

	// Initialize publisher
	pub := entity.NewPublisher()
	pub.AppendAddress("tcp://*:6602")

	context, _ := entity.CreateZMQCommEnv(true)
	defer context.Close()

	if err := pub.InitialBinding(context); err != nil {
		log.Fatalln("Initialize publisher failure.", err)
	}

	value := example.Test{}
	value.Label = proto.String("value1")
	value.Type = proto.Int32(0)

	for {
		time.Sleep(time.Second)
		*value.Type = value.GetType() + 2
		if err := pub.Send(filter, &value); err != nil {
			log.Println("Publish value failure.", err)
			break
		} else {
			log.Println("Publish value okay.")
		}
	}

}
Esempio n. 2
0
// NewClient creates a new instance of client.
func NewClient(address string) *Client {
	client := Client{}
	client.sub.AppendAddress(entity.Address(address))

	env, err := entity.CreateZMQCommEnv(true)
	if err != nil {
		return nil
	}
	if client.sub.InitialConnecting(env) != nil {
		return nil
	}
	return &client
}
Esempio n. 3
0
// NewServer creates a new Server instance.
func NewServer(address []string) *Server {
	server := Server{Interval: 1,
		data:      make(chan *model.TimeStruct),
		Generator: newTimeFormatData,
	}
	for _, val := range address {
		server.pub.AppendAddress(entity.Address(val))
	}
	env, err := entity.CreateZMQCommEnv(true)
	if err != nil {
		return nil
	}
	if server.pub.InitialBinding(env) != nil {
		return nil
	}
	return &server
}
Esempio n. 4
0
func main() {

	// Initialize subscriber
	sub := entity.NewSubscriber(filter)
	sub.AppendAddress("tcp://localhost:6602")

	context, _ := entity.CreateZMQCommEnv(true)
	defer context.Close()

	if err := sub.InitialConnecting(context); err != nil {
		log.Fatalln("Initialize subscriber failure.", err)
	}

	value := &example.TestHandler{}

	if err := sub.Subscribe(value); err != nil {
		log.Fatalln("Subscribe example.Test data type failure.")
	}

	log.Println("Start receiving datas.")

	sub.ReceivingEvent()
}