updated messaging handling

This commit is contained in:
Lorenzo Venerandi 2024-12-06 01:29:36 +01:00
parent 0acc7492bf
commit 85d9fbcc8b
3 changed files with 56 additions and 36 deletions

View File

@ -15,6 +15,11 @@ This is a simple TinyGo Wasm example that responds with a "Hello World" message
wash build 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 ## Running with wasmtime
You must have wasmtime 25.0.0 for this to work. Make sure to follow the build step above first. You must have wasmtime 25.0.0 for this to work. Make sure to follow the build step above first.

View File

@ -18,15 +18,11 @@ var messagingConsumer = &messagingConsumerAdapter{
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] { func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
logger := wasilog.ContextLogger("handleMessage") logger := wasilog.ContextLogger("handleMessage")
replyTo := msg.ReplyTo.Some()
logger.Info("Received message", "subject", msg.Subject) logger.Info("Received message", "subject", msg.Subject)
if replyTo != nil {
logger.Info("Sending reply", "subject", *replyTo)
reply := types.BrokerMessage{ reply := types.BrokerMessage{
Subject: *replyTo, Subject: msg.Subject + ".reply",
Body: msg.Body, Body: msg.Body,
ReplyTo: cm.None[string](), ReplyTo: cm.None[string](),
} }
@ -35,7 +31,6 @@ func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string]
logger.Error("Failed to send reply", "error", *res.Err()) logger.Error("Failed to send reply", "error", *res.Err())
return res return res
} }
}
return cm.OK[cm.Result[string, struct{}, string]](struct{}{}) return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
} }

View File

@ -10,38 +10,58 @@ metadata:
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
wasmcloud.dev/categories: | wasmcloud.dev/categories: |
http,outgoing-http,http-server,tinygo,golang,example http,outgoing-http,http-server,tinygo,golang,example
spec:
spec: spec:
components: components:
- name: http-component - name: echo
type: component type: component
properties: 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: traits:
# Govern the spread/scheduling of the component # Govern the spread/scheduling of the component
- type: spreadscaler - type: spreadscaler
properties: properties:
instances: 1 instances: 1
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
# Add a capability provider that enables HTTP access # so the `echo` component can make use of messaging interface functionality
- name: httpserver # (i.e. making interacting with the messaging system, in this case NATS)
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.
- type: link - type: link
properties: properties:
target: http-component target: nats
namespace: wasi namespace: wasmcloud
package: http package: messaging
interfaces: [incoming-handler] interfaces: [consumer]
source_config:
- name: default-http # Add a capability provider that implements `wasmcloud:messaging` using NATS
- name: nats
type: capability
properties: properties:
address: 127.0.0.1:8000 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: simple-subscription
properties:
subscriptions: wasmcloud.echo