Skip to content

v0.2.1 🐌 [snail] the "NATS" release

Pre-release
Pre-release
Compare
Choose a tag to compare
@k33g k33g released this 18 Sep 15:37
· 267 commits to main since this release
8da3975

This release brings you NATS support (1st stage). You can start Capsule as a NATS subscriber to listen to a specific subject and then reply.

This NATS integration is effortless (it could evolve in the future):

1- Start Capsule in the "NATS" mode:

capsule \
   -wasm=../wasm_modules/capsule-nats-subscriber/hello.wasm \
   -mode=nats \
   -natssrv=nats.devsecops.fun:4222 \
   -subject=ping

2- Write your NATS subscriber WASM module:

package main

import (
	hf "github.com/bots-garden/capsule/capsulemodule/hostfunctions"
)

func main() {
	hf.OnNatsMessage(Handle) // listening and trigger the Handle function at every message
}

func Handle(params []string) {
	hf.Log("👋 on subject: " + hf.NatsGetSubject() + ", 🎉 message" + params[0])
	// reply on another subject
	_, err := hf.NatsPublish("notify", "it's a wasm module here")

	if err != nil {
		hf.Log("😡 ouch something bad is happening")
		hf.Log(err.Error())
	}
}

New host functions:

  • OnNatsMessage
  • NatsPublish
  • NatsConnectPublish
  • NatsConnectPublish
  • NatsGetSubject
  • NatsGetServer

👀 at the README.md file for more details: https://github.com/bots-garden/capsule#first-nats-function