diff --git a/README.md b/README.md index 7860f36..53b3653 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/messaging.go b/messaging.go index fdd4765..e9d28b9 100644 --- a/messaging.go +++ b/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{}{}) diff --git a/wadm.yaml b/wadm.yaml index 053034f..7c1b8f4 100644 --- a/wadm.yaml +++ b/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