Documentation ¶
Index ¶
- Constants
- Variables
- type ConnState
- type ConnStateChangeCB
- type Dialer
- type Figg
- func (f *Figg) Close() error
- func (f *Figg) Publish(name string, data []byte, onACK func())
- func (f *Figg) PublishNoACK(name string, data []byte)
- func (f *Figg) PublishWaitForACK(name string, data []byte)
- func (f *Figg) Subscribe(name string, onMessage MessageCB, options ...TopicOption) error
- func (f *Figg) Unsubscribe(topic string)
- type Message
- type MessageCB
- type Option
- func WithConnStateChangeCB(cb ConnStateChangeCB) Option
- func WithDialer(dialer Dialer) Option
- func WithLogger(logger *zap.Logger) Option
- func WithMaxPingOut(maxPingOut int) Option
- func WithPingInterval(pingInterval time.Duration) Option
- func WithReadBufLen(readBufLen int) Option
- func WithReconnectBackoffCB(cb ReconnectBackoffCB) Option
- func WithWindowSize(windowSize int) Option
- type Options
- type ReconnectBackoffCB
- type TopicOption
- type TopicOptions
- type TopicState
Constants ¶
View Source
const ( DISCONNECTED = ConnState(iota) CONNECTED )
View Source
const ( DefaultReadBufLen = 1 << 15 // 32 KB DefaultWindowSize = 256 DefaultPingInterval = 2 * time.Second DefaultMaxPingOut = 2 )
View Source
const ( // ATTACHED when the client is connected and is received messages published // to the topic. ATTACHED = TopicState(iota) // ATTACHING when clients connection has dropped and will reattach once // connected. ATTACHING // DETACHED when the user has explicitly unsubscribed from the topic. DETACHED )
Variables ¶
View Source
var (
ErrAlreadySubscribed = errors.New("already subscribed")
)
View Source
var (
ErrNotConnected = errors.New("not connected")
)
Functions ¶
This section is empty.
Types ¶
type ConnStateChangeCB ¶
type ConnStateChangeCB func(state ConnState)
type Figg ¶
type Figg struct {
// contains filtered or unexported fields
}
func (*Figg) Publish ¶
Publish publishes the data to the given topic. When the server acknowledges the message onACK is called.
func (*Figg) PublishNoACK ¶
PublishNoACK is the same as Publish except it doesn't wait for the message to be acknowledged
func (*Figg) PublishWaitForACK ¶
PublishBlocking is similar to Publish except it will block waiting for the message is acknowledged. Note this will seriously limit thoughput so if high thoughput is needed use Publish and don't wait for messages to be acknowledged before sending the next.
func (*Figg) Subscribe ¶
func (f *Figg) Subscribe(name string, onMessage MessageCB, options ...TopicOption) error
Subscribe to the given topic.
Note only one subscriber is allowed per topic.
func (*Figg) Unsubscribe ¶
type Option ¶
type Option func(*Options)
func WithConnStateChangeCB ¶
func WithConnStateChangeCB(cb ConnStateChangeCB) Option
func WithDialer ¶
func WithLogger ¶
func WithMaxPingOut ¶
func WithPingInterval ¶
func WithReadBufLen ¶
func WithReconnectBackoffCB ¶
func WithReconnectBackoffCB(cb ReconnectBackoffCB) Option
func WithWindowSize ¶
type Options ¶
type Options struct { // Addr is the address of the Figg node. Addr string // ReadBufLen is the size of the read buffer ontop of the socket. ReadBufLen int // Dialer is a custom dialer to connect to the server. If nil uses // net.Dialer with a 5 second timeout. Dialer Dialer // ReconnectBackoffCB is a callback to define a custom backoff strategy // when attempting to reconnect to the server. If nil uses a default // strategy where the retry doubles after each attempt, starting with a // 1 second interval after the first attempt, a maximum wait of 30 // seconds, and adding 20% random jitter (see defaultReconnectBackoffCB). ReconnectBackoffCB ReconnectBackoffCB // ConnStateChangeCB is an optional callback called when the clients // connection state changes. Note this must not block. ConnStateChangeCB ConnStateChangeCB // WindowSize is the number of unacknowledged in-flight messages are allowed // before Publish blocking. Defaults to 256. WindowSize int // PingInterval is the time between sending pings. Defaults to 2 seconds. PingInterval time.Duration // MaxPingOut is the maximum number of pings that have not received a // pong before determining the connection has dropped. Defaults to 2. MaxPingOut int // Logger is a custom logger to log events, which should be configured with // the desired logging level. If nil no logging is used. Logger *zap.Logger }
type ReconnectBackoffCB ¶
type TopicOption ¶
type TopicOption func(*TopicOptions)
func WithOffset ¶
func WithOffset(offset uint64) TopicOption
type TopicOptions ¶
type TopicState ¶
type TopicState int
func (TopicState) String ¶
func (s TopicState) String() string
Click to show internal directories.
Click to hide internal directories.