1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00
Michael Hope 412fa0a3b1 nats: support wildcard subjects by changing the handler to take
nats.Message.

Also update the docs and examples.

Signed-off-by: Michael Hope <mlhx@google.com>
2017-04-21 20:46:45 +02:00

41 lines
705 B
Go

// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/nats"
)
func main() {
natsAdaptor := nats.NewAdaptorWithAuth("localhost:4222", 1234, "user", "pass")
work := func() {
natsAdaptor.On("hello", func(msg nats.Message) {
fmt.Println("hello")
})
natsAdaptor.On("hola", func(msg nats.Message) {
fmt.Println("hola")
})
data := []byte("o")
gobot.Every(1*time.Second, func() {
natsAdaptor.Publish("hello", data)
})
gobot.Every(5*time.Second, func() {
natsAdaptor.Publish("hola", data)
})
}
robot := gobot.NewRobot("natsBot",
[]gobot.Connection{natsAdaptor},
work,
)
robot.Start()
}