Compare commits
No commits in common. "a81063b8e1b1875a5af8f3bdbc172b36eb0835cb" and "072726dd06dd1f2953d8eb41c3ce3f907d829c35" have entirely different histories.
a81063b8e1
...
072726dd06
@ -48,4 +48,5 @@ RUN mkdir /app
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install go dependencies, build the wasm module, push it to the registry
|
# Install go dependencies, build the wasm module, push it to the registry
|
||||||
CMD ["sh", "-c", "go env -w GOFLAGS=-buildvcs=false && go mod download && go mod verify && wash build && wash push $REGISTRY build/*.wasm"]
|
#CMD ["sh", "-c", "go mod download && go mod verify && go mod tidy && wash build && wash push $REGISTRY build/*_s.wasm"]
|
||||||
|
CMD ["sh", "-c", "go env -w GOFLAGS=-buildvcs=false && go mod download && go mod verify && wash build && wash push $REGISTRY build/.wasm"]
|
43
main.go
43
main.go
@ -2,56 +2,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
logger "gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasi/logging/logging"
|
|
||||||
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/consumer"
|
|
||||||
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/handler"
|
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/handler"
|
||||||
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/types"
|
|
||||||
"github.com/bytecodealliance/wasm-tools-go/cm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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() {
|
func init() {
|
||||||
handler.Exports.HandleMessage = handleMessage
|
handler.Exports.HandleMessage = handleMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
|
||||||
|
|
||||||
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
|
||||||
|
|
||||||
// TODO implement the logic to get the destination topic from the config
|
|
||||||
// dest_topic := config.GetAll()
|
|
||||||
dest_topic := "finish"
|
|
||||||
|
|
||||||
// TASK
|
|
||||||
arg := cm.LiftString[string, *uint8, uint8](msg.Body.Data(), uint8(msg.Body.Len()))
|
|
||||||
|
|
||||||
result := exec_task(arg)
|
|
||||||
|
|
||||||
// Send reply
|
|
||||||
reply := types.BrokerMessage{
|
|
||||||
Subject: dest_topic,
|
|
||||||
Body: cm.ToList([]byte(result)),
|
|
||||||
ReplyTo: cm.None[string](),
|
|
||||||
}
|
|
||||||
|
|
||||||
res := messagingConsumer.Publish(reply)
|
|
||||||
if res.IsErr() {
|
|
||||||
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Since we don't run this program like a CLI, the `main` function is empty. Instead,
|
// 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.
|
// we call the `handleRequest` function when an HTTP request is received.
|
||||||
func main() {}
|
func main() {}
|
||||||
|
44
messaging.go
Normal file
44
messaging.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bytecodealliance/wasm-tools-go/cm"
|
||||||
|
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/consumer"
|
||||||
|
"gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasmcloud/messaging/types"
|
||||||
|
logger "gitea.rebus.ninja/lore/wasm-nats-stream-client/gen/wasi/logging/logging"
|
||||||
|
//config "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
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 handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||||
|
|
||||||
|
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
||||||
|
|
||||||
|
// TODO implement the logic to get the destination topic from the config
|
||||||
|
// dest_topic := config.GetAll()
|
||||||
|
dest_topic := "finish"
|
||||||
|
|
||||||
|
// TASK
|
||||||
|
|
||||||
|
|
||||||
|
// Send reply
|
||||||
|
reply := types.BrokerMessage{
|
||||||
|
Subject: dest_topic,
|
||||||
|
Body: msg.Body,
|
||||||
|
ReplyTo: cm.None[string](),
|
||||||
|
}
|
||||||
|
res := messagingConsumer.Publish(reply)
|
||||||
|
if res.IsErr() {
|
||||||
|
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user