Compare commits
3 Commits
ea8a3ee209
...
85d9fbcc8b
Author | SHA1 | Date | |
---|---|---|---|
85d9fbcc8b | |||
0acc7492bf | |||
ca0df8edde |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
gen/*
|
||||
build/*
|
||||
|
||||
creds.json
|
@ -15,6 +15,11 @@ This is a simple TinyGo Wasm example that responds with a "Hello World" message
|
||||
wash build
|
||||
```
|
||||
|
||||
## Push OCI Artifact to Gitea
|
||||
```bash
|
||||
wash push gitea.rebus.ninja/lore/go-nats-client:1.x.x build/go_nats_client_s.wasm
|
||||
```
|
||||
|
||||
## Running with wasmtime
|
||||
|
||||
You must have wasmtime 25.0.0 for this to work. Make sure to follow the build step above first.
|
||||
|
4
go.mod
4
go.mod
@ -11,9 +11,9 @@ require (
|
||||
require (
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/regclient/regclient v0.7.1 // indirect
|
||||
github.com/regclient/regclient v0.7.2 // indirect
|
||||
github.com/samber/lo v1.47.0 // indirect
|
||||
github.com/samber/slog-common v0.17.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
|
12
go.sum
12
go.sum
@ -7,16 +7,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
|
||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||
github.com/olareg/olareg v0.1.0 h1:1dXBOgPrig5N7zoXyIZVQqU0QBo6sD9pbL6UYjY75CA=
|
||||
github.com/olareg/olareg v0.1.0/go.mod h1:RBuU7JW7SoIIxZKzLRhq8sVtQeAHzCAtRrXEBx2KlM4=
|
||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
||||
github.com/olareg/olareg v0.1.1 h1:Ui7q93zjcoF+U9U71sgqgZWByDoZOpqHitUXEu2xV+g=
|
||||
github.com/olareg/olareg v0.1.1/go.mod h1:w8NP4SWrHHtxsFaUiv1lnCnYPm4sN1seCd2h7FK/dc0=
|
||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/regclient/regclient v0.7.1 h1:qEsJrTmZd98fZKjueAbrZCSNGU+ifnr6xjlSAs3WOPs=
|
||||
github.com/regclient/regclient v0.7.1/go.mod h1:+w/BFtJuw0h0nzIw/z2+1FuA2/dVXBzDq4rYmziJpMc=
|
||||
github.com/regclient/regclient v0.7.2 h1:vcldDAwBMLtighYVMeb6qNt5+0hKg3AN2IkCc0JIJNM=
|
||||
github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ=
|
||||
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
||||
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
||||
github.com/samber/slog-common v0.17.1 h1:jTqqLBgoJshpoxlPSGiypyOanjH6tY+i9bwyYmIbjhI=
|
||||
|
7
main.go
7
main.go
@ -2,9 +2,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/handler"
|
||||
)
|
||||
|
||||
@ -12,10 +9,6 @@ func init() {
|
||||
handler.Exports.HandleMessage = handleMessage
|
||||
}
|
||||
|
||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello from Go!\n")
|
||||
}
|
||||
|
||||
// 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() {}
|
||||
|
23
messaging.go
23
messaging.go
@ -18,23 +18,18 @@ var messagingConsumer = &messagingConsumerAdapter{
|
||||
|
||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||
logger := wasilog.ContextLogger("handleMessage")
|
||||
replyTo := msg.ReplyTo.Some()
|
||||
|
||||
logger.Info("Received message", "subject", msg.Subject)
|
||||
|
||||
if replyTo != nil {
|
||||
logger.Info("Sending reply", "subject", *replyTo)
|
||||
|
||||
reply := types.BrokerMessage{
|
||||
Subject: *replyTo,
|
||||
Body: msg.Body,
|
||||
ReplyTo: cm.None[string](),
|
||||
}
|
||||
res := messagingConsumer.Publish(reply)
|
||||
if res.IsErr() {
|
||||
logger.Error("Failed to send reply", "error", *res.Err())
|
||||
return res
|
||||
}
|
||||
reply := types.BrokerMessage{
|
||||
Subject: msg.Subject + ".reply",
|
||||
Body: msg.Body,
|
||||
ReplyTo: cm.None[string](),
|
||||
}
|
||||
res := messagingConsumer.Publish(reply)
|
||||
if res.IsErr() {
|
||||
logger.Error("Failed to send reply", "error", *res.Err())
|
||||
return res
|
||||
}
|
||||
|
||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
||||
|
64
wadm.yaml
64
wadm.yaml
@ -10,38 +10,58 @@ metadata:
|
||||
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
||||
wasmcloud.dev/categories: |
|
||||
http,outgoing-http,http-server,tinygo,golang,example
|
||||
spec:
|
||||
spec:
|
||||
components:
|
||||
- name: http-component
|
||||
- name: echo
|
||||
type: component
|
||||
properties:
|
||||
image: file://./build/http_hello_world_s.wasm
|
||||
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
||||
# image: file://./build/echo_messaging_s.wasm
|
||||
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
||||
id: echo
|
||||
traits:
|
||||
# Govern the spread/scheduling of the component
|
||||
- type: spreadscaler
|
||||
properties:
|
||||
instances: 1
|
||||
|
||||
# Add a capability provider that enables HTTP access
|
||||
- name: httpserver
|
||||
type: capability
|
||||
properties:
|
||||
image: ghcr.io/wasmcloud/http-server:0.23.2
|
||||
traits:
|
||||
# Link the httpserver to the component, and configure the HTTP server
|
||||
# to listen on port 8000 for incoming requests
|
||||
#
|
||||
# Since the HTTP server calls the `http-component` component, we establish
|
||||
# a unidirectional link from this `httpserver` provider (the "source")
|
||||
# to the `http-component` component (the "target"), so the server can invoke
|
||||
# the component to handle a request.
|
||||
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
||||
# so the `echo` component can make use of messaging interface functionality
|
||||
# (i.e. making interacting with the messaging system, in this case NATS)
|
||||
- type: link
|
||||
properties:
|
||||
target: http-component
|
||||
namespace: wasi
|
||||
package: http
|
||||
interfaces: [incoming-handler]
|
||||
target: nats
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [consumer]
|
||||
|
||||
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
||||
- name: nats
|
||||
type: capability
|
||||
properties:
|
||||
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
||||
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
||||
# config:
|
||||
# - name: otel
|
||||
# properties:
|
||||
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
||||
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
||||
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
||||
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
||||
traits:
|
||||
# Since the `nats` capability provider calls an component to handle messages
|
||||
# coming over subscriptions, this provider needs a unidirectional link to the
|
||||
# component that wil be called.
|
||||
#
|
||||
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
||||
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
||||
- type: link
|
||||
properties:
|
||||
target: echo
|
||||
namespace: wasmcloud
|
||||
package: messaging
|
||||
interfaces: [handler]
|
||||
source_config:
|
||||
- name: default-http
|
||||
- name: simple-subscription
|
||||
properties:
|
||||
address: 127.0.0.1:8000
|
||||
subscriptions: wasmcloud.echo
|
||||
|
@ -1,9 +1,13 @@
|
||||
name = "http-hello-world"
|
||||
name = "go_nats_client"
|
||||
language = "tinygo"
|
||||
type = "component"
|
||||
version = "0.1.0"
|
||||
version = "1.0.0"
|
||||
|
||||
[component]
|
||||
wit_world = "hello"
|
||||
wasm_target = "wasm32-wasip2"
|
||||
destination = "build/http_hello_world_s.wasm"
|
||||
destination = "build/go_nats_client_s.wasm"
|
||||
|
||||
[registry]
|
||||
url = "gitea.rebus.ninja/lore"
|
||||
credentials = "./creds.json"
|
Loading…
Reference in New Issue
Block a user