Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 1.18 KB

README.md

File metadata and controls

85 lines (59 loc) · 1.18 KB

Stallion Golang SDK


Golang client SDK for Stallion message broker.

How to use?

Get package:

go get github.com/official-stallion/go-sdk@latest

Creating Clients

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)
	}
}

Subscribe on a topic

client.Subscribe("topic", func(data []byte) {
    // any handler that you want
    fmt.Println(string(data))
})

Publish over a topic

client.Publish("topic", []byte("Hello"))

Unsubscribe from a topic

client.Unsubscribe("topic")

Connect with Auth

Connect with username and password set in url:

client, err := stallion.NewClient("st://root:Pa$$word@localhost:9090")
if err != nil {
    panic(err)
}

Mock

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"))
}