gulsar
Pulsar WebSocket Client Library for Go.
Requirement
Go 1.8
Installation
go get github.com/kpango/gulsar
Example
package main
import (
"context"
"time"
"github.com/kpango/glg"
"github.com/kpango/gulsar"
)
func main() {
g := gulsar.New("http://localhost", "wss://pulsar:port/path/topic")
g.SetTlsCredential("sample.cert", "sample.key")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
g.ConnectWithHeader(ctx, map[string][]string{
"Auth-Header-Key": {
"Token",
},
})
ticker := time.NewTicker(time.Second * 3)
go func() {
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
err := g.Produce(&gulsar.ProduceMessage{})
if err != nil {
glg.Error(err)
continue
}
ackMsg, err := g.ReceiveACK()
if err != nil {
glg.Error(err)
continue
}
glg.Info(ackMsg)
}
}
}()
for {
select {
case <-ctx.Done():
return
default:
msg, err := g.Consume()
if err != nil {
glg.Error(err)
continue
}
glg.Info(string(msg.Body))
g.SendACK(msg.MessageID)
}
}
}
Contribution
- Fork it ( https://github.com/kpango/gulsar/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
Author
LICENSE
gulsar released under MIT license, refer LICENSE file.