Golang client SDK for Stallion message broker.
Get package:
go get github.com/official-stallion/go-sdk@latest
You can connect to stallion server like the example below:
package main
import (
"fmt"
"time"
sdk "github.com/official-stallion/go-sdk"
)
func main() {
client, err := sdk.NewClient("st://localhost:9090")
if err != nil {
panic(err)
}
}
client.Subscribe("topic", func(data []byte) {
// any handler that you want
fmt.Println(string(data))
})
client.Publish("topic", []byte("Hello"))
client.Unsubscribe("topic")
Connect with username and password set in url:
client, err := stallion.NewClient("st://root:Pa$$word@localhost:9090")
if err != nil {
panic(err)
}
You can create a mock client to create a stallion client sample:
package main
import sdk "github.com/official-stallion/go-sdk"
func main() {
client := sdk.NewMockClient()
client.Publish("topic", []byte("message"))
}