summaryrefslogtreecommitdiff
path: root/cmd/publisher/main.go
blob: 24125b13b8dd3d0b36342e2119ec0347b66ee940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"c0/gatekeeper/pkg/x"
	"fmt"
	"time"

	"github.com/gobuffalo/buffalo/worker"
	"github.com/nats-io/nats.go"
)

func main() {
	connection := x.Must(nats.Connect(nats.DefaultURL))
	defer connection.Close()

	stream := x.Must(connection.JetStream())

	for i := 0; 1 == 1; i++ {
		reply := x.Must(stream.Publish("gtkpr.jobs.job_1", []byte(worker.Args{"message": i}.String())))
		fmt.Printf("job: %v %v\n", i, reply)

		if i%2 == 0 {
			reply := x.Must(stream.Publish("gtkpr.event.even", []byte(worker.Args{"even": i}.String())))
			fmt.Printf("even: %v %v\n", i, reply)
		} else {
			reply := x.Must(stream.Publish("gtkpr.event.odd", []byte(worker.Args{"odd": i}.String())))
			fmt.Printf("odd: %v %v\n", i, reply)
		}

		time.Sleep(1000 * time.Millisecond)
	}
}