added destination topic to config
This commit is contained in:
parent
ac9a119eb5
commit
cb51ae31e7
@ -5,6 +5,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime"
|
||||||
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__consumer "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__consumer "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||||
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__types "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
gitea_rebus_ninja__lore__go___nats___client__gen__wasmcloud__messaging__types "gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||||
github_com__bytecodealliance__wasm___tools___go__cm "github.com/bytecodealliance/wasm-tools-go/cm"
|
github_com__bytecodealliance__wasm___tools___go__cm "github.com/bytecodealliance/wasm-tools-go/cm"
|
||||||
@ -17,6 +18,46 @@ const _ string = runtime.Compiler
|
|||||||
|
|
||||||
var _ unsafe.Pointer
|
var _ unsafe.Pointer
|
||||||
|
|
||||||
|
//go:linkname wasmimport_Get gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime.wasmimport_Get
|
||||||
|
func wasmimport_Get(key0 *uint8, key1 uint32, result *github_com__bytecodealliance__wasm___tools___go__cm.Result[gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.OptionStringShape, github_com__bytecodealliance__wasm___tools___go__cm.Option[string], gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigError]) {
|
||||||
|
var __p runtime.Pinner
|
||||||
|
defer __p.Unpin()
|
||||||
|
if __err := wadge.WithCurrentInstance(func(__instance *wadge.Instance) error {
|
||||||
|
return __instance.Call("wasi:config/runtime@0.2.0-draft", "get", func() unsafe.Pointer {
|
||||||
|
ptr := unsafe.Pointer(key0)
|
||||||
|
__p.Pin(ptr)
|
||||||
|
return ptr
|
||||||
|
}(), func() unsafe.Pointer {
|
||||||
|
ptr := unsafe.Pointer(&key1)
|
||||||
|
__p.Pin(ptr)
|
||||||
|
return ptr
|
||||||
|
}(), func() unsafe.Pointer {
|
||||||
|
ptr := unsafe.Pointer(result)
|
||||||
|
__p.Pin(ptr)
|
||||||
|
return ptr
|
||||||
|
}())
|
||||||
|
}); __err != nil {
|
||||||
|
wadge.CurrentErrorHandler()(__err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:linkname wasmimport_GetAll gitea.rebus.ninja/lore/go-nats-client/gen/wasi/config/runtime.wasmimport_GetAll
|
||||||
|
func wasmimport_GetAll(result *github_com__bytecodealliance__wasm___tools___go__cm.Result[gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigErrorShape, github_com__bytecodealliance__wasm___tools___go__cm.List[[2]string], gitea_rebus_ninja__lore__go___nats___client__gen__wasi__config__runtime.ConfigError]) {
|
||||||
|
var __p runtime.Pinner
|
||||||
|
defer __p.Unpin()
|
||||||
|
if __err := wadge.WithCurrentInstance(func(__instance *wadge.Instance) error {
|
||||||
|
return __instance.Call("wasi:config/runtime@0.2.0-draft", "get-all", func() unsafe.Pointer {
|
||||||
|
ptr := unsafe.Pointer(result)
|
||||||
|
__p.Pin(ptr)
|
||||||
|
return ptr
|
||||||
|
}())
|
||||||
|
}); __err != nil {
|
||||||
|
wadge.CurrentErrorHandler()(__err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//go:linkname wasmimport_Log gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging.wasmimport_Log
|
//go:linkname wasmimport_Log gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging.wasmimport_Log
|
||||||
func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
|
func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
|
||||||
var __p runtime.Pinner
|
var __p runtime.Pinner
|
||||||
|
79
messaging.go
79
messaging.go
@ -1,35 +1,44 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bytecodealliance/wasm-tools-go/cm"
|
"github.com/bytecodealliance/wasm-tools-go/cm"
|
||||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||||
logger "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging"
|
logger "gitea.rebus.ninja/lore/go-nats-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])
|
type messagingConsumerAdapter struct {
|
||||||
}
|
Publish func(msg types.BrokerMessage) (result cm.Result[string, struct{}, string])
|
||||||
|
}
|
||||||
// NOTE(lxf): this is overridden in tests
|
|
||||||
var messagingConsumer = &messagingConsumerAdapter{
|
// NOTE(lxf): this is overridden in tests
|
||||||
Publish: consumer.Publish,
|
var messagingConsumer = &messagingConsumerAdapter{
|
||||||
}
|
Publish: consumer.Publish,
|
||||||
|
}
|
||||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
|
||||||
|
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||||
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
|
||||||
|
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
||||||
reply := types.BrokerMessage{
|
|
||||||
Subject: msg.Subject + ".reply",
|
// TODO implement the logic to get the destination topic from the config
|
||||||
Body: msg.Body,
|
// dest_topic := config.GetAll()
|
||||||
ReplyTo: cm.None[string](),
|
dest_topic := msg.Subject + ".reply"
|
||||||
}
|
|
||||||
res := messagingConsumer.Publish(reply)
|
// TASK
|
||||||
if res.IsErr() {
|
|
||||||
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
|
||||||
return res
|
// Send reply
|
||||||
}
|
reply := types.BrokerMessage{
|
||||||
|
Subject: dest_topic,
|
||||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
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{}{})
|
||||||
|
}
|
||||||
|
162
wadm.yaml
162
wadm.yaml
@ -1,79 +1,83 @@
|
|||||||
apiVersion: core.oam.dev/v1beta1
|
apiVersion: core.oam.dev/v1beta1
|
||||||
kind: Application
|
kind: Application
|
||||||
metadata:
|
metadata:
|
||||||
name: tinygo-hello-world
|
name: tinygo-hello-world
|
||||||
annotations:
|
annotations:
|
||||||
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
|
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
|
||||||
wasmcloud.dev/authors: wasmCloud team
|
wasmcloud.dev/authors: wasmCloud team
|
||||||
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
|
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
|
||||||
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
|
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
|
||||||
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:
|
||||||
components:
|
components:
|
||||||
- name: echo
|
- name: echo
|
||||||
type: component
|
type: component
|
||||||
properties:
|
properties:
|
||||||
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
# 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: file://./build/echo_messaging_s.wasm
|
||||||
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
||||||
id: echo
|
id: echo
|
||||||
traits:
|
config:
|
||||||
# Govern the spread/scheduling of the component
|
- name: nats-topic
|
||||||
- type: spreadscaler
|
properties:
|
||||||
properties:
|
dest-topic: wasmcloud.echo.reply
|
||||||
instances: 1
|
traits:
|
||||||
spread:
|
# Govern the spread/scheduling of the component
|
||||||
- name: edge
|
- type: spreadscaler
|
||||||
weight: 100
|
properties:
|
||||||
requirements:
|
instances: 1
|
||||||
host-type: edge
|
spread:
|
||||||
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
- name: edge
|
||||||
# so the `echo` component can make use of messaging interface functionality
|
weight: 100
|
||||||
# (i.e. making interacting with the messaging system, in this case NATS)
|
requirements:
|
||||||
- type: link
|
host-type: edge
|
||||||
properties:
|
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
||||||
target: nats
|
# so the `echo` component can make use of messaging interface functionality
|
||||||
namespace: wasmcloud
|
# (i.e. making interacting with the messaging system, in this case NATS)
|
||||||
package: messaging
|
- type: link
|
||||||
interfaces: [consumer]
|
properties:
|
||||||
|
target: nats
|
||||||
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
namespace: wasmcloud
|
||||||
- name: nats
|
package: messaging
|
||||||
type: capability
|
interfaces: [consumer]
|
||||||
properties:
|
|
||||||
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
||||||
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
- name: nats
|
||||||
# config:
|
type: capability
|
||||||
# - name: otel
|
properties:
|
||||||
# properties:
|
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
||||||
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
||||||
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
# config:
|
||||||
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
# - name: otel
|
||||||
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
# properties:
|
||||||
traits:
|
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
||||||
# Since the `nats` capability provider calls an component to handle messages
|
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
||||||
# coming over subscriptions, this provider needs a unidirectional link to the
|
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
||||||
# component that wil be called.
|
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
||||||
#
|
traits:
|
||||||
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
# Since the `nats` capability provider calls an component to handle messages
|
||||||
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
# coming over subscriptions, this provider needs a unidirectional link to the
|
||||||
- type: link
|
# component that wil be called.
|
||||||
properties:
|
#
|
||||||
target: echo
|
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
||||||
namespace: wasmcloud
|
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
||||||
package: messaging
|
- type: link
|
||||||
interfaces: [handler]
|
properties:
|
||||||
source_config:
|
target: echo
|
||||||
- name: simple-subscription
|
namespace: wasmcloud
|
||||||
properties:
|
package: messaging
|
||||||
subscriptions: wasmcloud.echo
|
interfaces: [handler]
|
||||||
- type: spreadscaler
|
source_config:
|
||||||
properties:
|
- name: simple-subscription
|
||||||
instances: 1
|
properties:
|
||||||
spread:
|
subscriptions: wasmcloud.echo
|
||||||
- name: edge
|
- type: spreadscaler
|
||||||
weight: 100
|
properties:
|
||||||
requirements:
|
instances: 1
|
||||||
host-type: edge
|
spread:
|
||||||
|
- name: edge
|
||||||
|
weight: 100
|
||||||
|
requirements:
|
||||||
|
host-type: edge
|
||||||
|
@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[[packages]]
|
||||||
|
name = "wasi:config"
|
||||||
|
registry = "wasi.dev"
|
||||||
|
|
||||||
|
[[packages.versions]]
|
||||||
|
requirement = "=0.2.0-draft"
|
||||||
|
version = "0.2.0-draft"
|
||||||
|
digest = "sha256:aa2d36d0843999edad80a13bf22f4529277f7b6012429f8a5d1f9499f3793c1a"
|
||||||
|
|
||||||
[[packages]]
|
[[packages]]
|
||||||
name = "wasi:logging"
|
name = "wasi:logging"
|
||||||
registry = "wasi.dev"
|
registry = "wasi.dev"
|
||||||
|
Loading…
Reference in New Issue
Block a user