Luis Figueiredo il y a 8 ans
commit
928210ad66
4 fichiers modifiés avec 62 ajouts et 0 suppressions
  1. 1 0
      main.go
  2. 30 0
      publisher/main.go
  3. 1 0
      subscriptor/main.go
  4. 30 0
      subscriptor/publisher/main.go

+ 1 - 0
main.go

@@ -0,0 +1 @@
+

+ 30 - 0
publisher/main.go

@@ -0,0 +1,30 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"math/rand"
+	"time"
+
+	"github.com/ably/ably-go/ably"
+)
+
+func main() {
+	opt := &ably.ClientOptions{}
+	opt.Key = "kY92tg.1qo8DQ:CS755GfXwEGtBiIr"
+	a, err := ably.NewRealtimeClient(opt)
+	panicIfErr(err)
+	chn := a.Channels.Get("test")
+	for {
+		log.Println("Sending:")
+		chn.Publish("test", fmt.Sprintf("Hello: %d", rand.Intn(10)))
+		<-time.After(2 * time.Second)
+	}
+
+}
+
+func panicIfErr(err error) {
+	if err != nil {
+		panic(err)
+	}
+}

+ 1 - 0
subscriptor/main.go

@@ -0,0 +1 @@
+

+ 30 - 0
subscriptor/publisher/main.go

@@ -0,0 +1,30 @@
+package main
+
+import (
+	"fmt"
+	"log"
+	"math/rand"
+	"time"
+
+	"github.com/ably/ably-go/ably"
+)
+
+func main() {
+	opt := &ably.ClientOptions{}
+	opt.Key = "kY92tg.1qo8DQ:CS755GfXwEGtBiIr"
+	a, err := ably.NewRealtimeClient(opt)
+	panicIfErr(err)
+	chn := a.Channels.Get("test")
+	for {
+		log.Println("Sending:")
+		chn.Publish("test", fmt.Sprintf("Hello: %d", rand.Intn(10)))
+		<-time.After(2 * time.Second)
+	}
+
+}
+
+func panicIfErr(err error) {
+	if err != nil {
+		panic(err)
+	}
+}