34 lines
915 B
Go
34 lines
915 B
Go
package darwingeststomp
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
stomp "github.com/go-stomp/stomp/v3"
|
|
)
|
|
|
|
type Config struct {
|
|
Hostname string
|
|
Username, Password string
|
|
ClientID string
|
|
}
|
|
|
|
func Dial(ctx context.Context, cfg Config) (*stomp.Conn, error) {
|
|
const maxExpectedQPS = 60
|
|
var maxExpectedDowntime = int((10 * time.Minute).Seconds())
|
|
return stomp.Dial(
|
|
"tcp", cfg.Hostname,
|
|
stomp.ConnOpt.Login(cfg.Username, cfg.Password),
|
|
stomp.ConnOpt.Header("client-id", cfg.ClientID),
|
|
stomp.ConnOpt.ReadChannelCapacity(maxExpectedQPS*maxExpectedDowntime),
|
|
stomp.ConnOpt.HeartBeat(7*time.Minute, 1*time.Minute),
|
|
stomp.ConnOpt.HeartBeatGracePeriodMultiplier(3),
|
|
)
|
|
}
|
|
|
|
func Subscribe(c *stomp.Conn, subName string) (*stomp.Subscription, error) {
|
|
return c.Subscribe(
|
|
"/topic/darwin.pushport-v16", stomp.AckClientIndividual,
|
|
stomp.SubscribeOpt.Header("durable-subscription-name", subName),
|
|
)
|
|
}
|