-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqs.go
45 lines (37 loc) · 1013 Bytes
/
sqs.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Copyright (C) 2021 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the Apache License Version 2.0. See the LICENSE file for details.
// https://github.com/fogfish/swarm
//
package main
import (
"log/slog"
"github.com/fogfish/swarm"
"github.com/fogfish/swarm/broker/sqs"
"github.com/fogfish/swarm/dequeue"
"github.com/fogfish/swarm/kernel/encoding"
)
func main() {
q, err := sqs.NewDequeuer("swarm-test",
sqs.WithConfig(
swarm.WithLogStdErr(),
),
)
if err != nil {
slog.Error("sqs reader has failed", "err", err)
return
}
go actor("user").handle(dequeue.Bytes(q, encoding.ForBytes("User")))
go actor("note").handle(dequeue.Bytes(q, encoding.ForBytes("Note")))
go actor("like").handle(dequeue.Bytes(q, encoding.ForBytes("Like")))
q.Await()
}
type actor string
func (a actor) handle(rcv <-chan swarm.Msg[[]byte], ack chan<- swarm.Msg[[]byte]) {
for msg := range rcv {
slog.Info("Event", "type", a, "msg", msg.Object)
ack <- msg
}
}