-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eventbridge add example of sending binary data
- Loading branch information
Showing
9 changed files
with
112 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Copyright (C) 2021 - 2024 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/eventbridge" | ||
"github.com/fogfish/swarm/dequeue" | ||
) | ||
|
||
func main() { | ||
q, err := eventbridge.NewReader("swarm-example-eventbridge", | ||
eventbridge.WithConfig( | ||
swarm.WithLogStdErr(), | ||
), | ||
) | ||
if err != nil { | ||
slog.Error("eventbridge reader has failed", "err", err) | ||
return | ||
} | ||
|
||
// | ||
go actor("user").handle(dequeue.Bytes(q, "User")) | ||
go actor("note").handle(dequeue.Bytes(q, "Note")) | ||
go actor("like").handle(dequeue.Bytes(q, "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", string(msg.Object)) | ||
ack <- msg | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright (C) 2021 - 2024 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/eventbridge" | ||
"github.com/fogfish/swarm/enqueue" | ||
) | ||
|
||
func main() { | ||
q, err := eventbridge.NewWriter("swarm-example-eventbridge", | ||
eventbridge.WithConfig( | ||
swarm.WithSource("swarm-example-eventbridge"), | ||
swarm.WithLogStdErr(), | ||
), | ||
) | ||
if err != nil { | ||
slog.Error("eventbridge writer has failed", "err", err) | ||
return | ||
} | ||
|
||
user := swarm.LogDeadLetters(enqueue.Bytes(q, "User")) | ||
note := swarm.LogDeadLetters(enqueue.Bytes(q, "Note")) | ||
like := swarm.LogDeadLetters(enqueue.Bytes(q, "Like")) | ||
|
||
user <- []byte(`User Signed in`) | ||
note <- []byte(`User wrote note`) | ||
like <- []byte(`User liked note`) | ||
|
||
q.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters