Пример #1
0
func main() {
	// e := &authExtn{"abcdef0123456789"}
	// e2 := &spyExtn{}
	url := "http://localhost:5000/faye"

	wray.RegisterTransports([]wray.Transport{&wray.HTTPTransport{}})
	faye := wray.NewFayeClient(url)
	// faye.AddExtension(e)
	// faye.AddExtension(e2)

	go faye.Listen()

	// when sent this message will have the auth token added to it
	faye.Publish("/test", map[string]interface{}{"hello": "world"})
}
Пример #2
0
func main() {
	wray.RegisterTransports([]wray.Transport{&wray.HTTPTransport{}})
	// wray.RegisterTransports([]wray.Transport{&wray.HttpTransport{}})
	client := wray.NewFayeClient("http://localhost:5000/faye")
	client.AddExtension(client) // log all packets in/out

	go client.Listen()

	fmt.Print("****** PUBLISH EXAMPLE ******\n\n")

	params := map[string]interface{}{"hello": "from golang"}

	for {
		err := client.Publish("/foo", params)
		if err != nil {
			fmt.Printf("\n[ERROR] %s\n\n", err)
		}

		time.Sleep(2 * time.Second)
	}
}
Пример #3
0
func main() {
	wray.RegisterTransports([]wray.Transport{&wray.HTTPTransport{}})
	client := wray.NewFayeClient("http://localhost:5000/faye")
	client.AddExtension(client) // log all packets in/out
	go client.Listen()

	fmt.Print("****** SIMPLE SUBSCRIBE EXAMPLE ******\n\n")

	go func() {
		for {
			client.Publish("/foo", map[string]interface{}{"hello": "from foo"})
			time.Sleep(2 * time.Second)
		}
	}()

	msgChan, _ := client.Subscribe("/foo")
	for {
		msg := <-msgChan
		fmt.Println("-------------------------------------------")
		fmt.Println(msg.Data())
	}
}
Пример #4
0
func main() {
	wray.RegisterTransports([]wray.Transport{&wray.HTTPTransport{}})
	client := wray.NewFayeClient("http://localhost:5000/faye")
	client.AddExtension(client) // log all packets in/out
	go client.Listen()

	chans := []chan wray.Message{
		make(chan wray.Message),
		make(chan wray.Message),
		make(chan wray.Message),
	}

	fmt.Print("****** COMPLEX SUBSCRIBE EXAMPLE ******\n\n")

	go client.WaitSubscribe("/foo", chans[0])
	go client.WaitSubscribe("/bar", chans[1])
	go client.WaitSubscribe("/baz", chans[2])

	go func() {
		for {
			client.Publish("/foo", map[string]interface{}{"hello": "from foo"})
			client.Publish("/bar", map[string]interface{}{"hello": "from bar"})
			client.Publish("/baz", map[string]interface{}{"hello": "from baz"})
			time.Sleep(2 * time.Second)
		}
	}()

	for {
		select {
		case msg := <-chans[0]:
			go printMsg(msg)
		case msg := <-chans[1]:
			go printMsg(msg)
		case msg := <-chans[2]:
			go printMsg(msg)
		}
	}
}