53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
//go:generate go run github.com/bytecodealliance/wasm-tools-go/cmd/wit-bindgen-go generate --world hello --out gen ./wit
|
|
package main
|
|
|
|
import (
|
|
|
|
logger "gitea.rebus.ninja/lore/wasm-nats-producer-client/gen/wasi/logging/logging"
|
|
"gitea.rebus.ninja/lore/wasm-nats-producer-client/gen/wasmcloud/messaging/consumer"
|
|
"gitea.rebus.ninja/lore/wasm-nats-producer-client/gen/wasmcloud/messaging/types"
|
|
"github.com/bytecodealliance/wasm-tools-go/cm"
|
|
"time"
|
|
)
|
|
|
|
type messagingConsumerAdapter struct {
|
|
Publish func(msg types.BrokerMessage) (result cm.Result[string, struct{}, string])
|
|
}
|
|
|
|
// NOTE(lxf): this is overridden in tests
|
|
var messagingConsumer = &messagingConsumerAdapter{
|
|
Publish: consumer.Publish,
|
|
}
|
|
|
|
|
|
func init() {
|
|
sendMessage()
|
|
}
|
|
|
|
func sendMessage() {
|
|
|
|
for {
|
|
|
|
dest_topic := "streaming"
|
|
|
|
message := "test"
|
|
// Send reply
|
|
reply := types.BrokerMessage{
|
|
Subject: dest_topic,
|
|
Body: cm.ToList([]byte(message)),
|
|
ReplyTo: cm.None[string](),
|
|
}
|
|
|
|
res := messagingConsumer.Publish(reply)
|
|
if res.IsErr() {
|
|
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
|
}
|
|
}
|
|
|
|
// Since we don't run this program like a CLI, the `main` function is empty. Instead,
|
|
// we call the `handleRequest` function when an HTTP request is received.
|
|
func main() {}
|