Skip to content

official-stallion/client.go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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