Documentation
¶
Index ¶
- Constants
- Variables
- func IsClosed(topic string) bool
- type AbstractClient
- type DefaultMessageHandler
- type GoroutineClient
- type GoroutinePooledClient
- type IMessage
- type Message
- type MessageBatchHandler
- type MessageHandler
- type PollingClient
- type RingBuffer
- type StreamDeserializer
- type StreamDeserializerOption
- type SubscribeRequest
- type T
- type TableMessage
- type TopicPoller
- type UnboundedChan
Constants ¶
const (
// DefaultPort is default listening port.
DefaultPort = 8848
)
Variables ¶
var ErrIsEmpty = errors.New("ringbuffer is empty")
var (
TCPNetWork = "tcp"
)
Functions ¶
Types ¶
type AbstractClient ¶
type AbstractClient interface {
// UnSubscribe helps you to unsubscribe the specific action of the table according to the req
UnSubscribe(req *SubscribeRequest) error
// IsClose checks whether the client is close
IsClosed() bool
// contains filtered or unexported methods
}
AbstractClient is the client interface for streaming subscription.
type DefaultMessageHandler ¶
type DefaultMessageHandler struct {
// contains filtered or unexported fields
}
DefaultMessageHandler is an implementation of MessageHandler, which is the default handler of IMessage.
func (*DefaultMessageHandler) DoEvent ¶
func (d *DefaultMessageHandler) DoEvent(msg IMessage)
DoEvent will be called when you subscribe with a goroutineClient or a goroutinePooledClient.
type GoroutineClient ¶
type GoroutineClient struct {
// contains filtered or unexported fields
}
GoroutineClient is an implementation of AbstractClient for streaming subscription.
func NewGoroutineClient ¶
func NewGoroutineClient(listeningHost string, listeningPort int) *GoroutineClient
NewGoroutineClient instantiates an instance of GoroutineClient, which is used to listen on the listening port to receive subscription info. When listeningHost is "", the default host is the local address. When listeningPort is 0, enable the reverse stream subscription.
func (*GoroutineClient) Close ¶
func (t *GoroutineClient) Close()
Close closes the client and stop subscribing.
func (*GoroutineClient) IsClosed ¶
func (t *GoroutineClient) IsClosed() bool
IsClosed checks whether the client is closed.
func (*GoroutineClient) Subscribe ¶
func (t *GoroutineClient) Subscribe(req *SubscribeRequest) error
Subscribe helps you to subscribe the specific action of the table according to the req.
func (*GoroutineClient) UnSubscribe ¶
func (t *GoroutineClient) UnSubscribe(req *SubscribeRequest) error
UnSubscribe helps you to unsubscribe the specific action of the table according to the req.
type GoroutinePooledClient ¶
type GoroutinePooledClient struct {
// contains filtered or unexported fields
}
GoroutinePooledClient is an implementation of AbstractClient for streaming subscription.
func NewGoroutinePooledClient ¶
func NewGoroutinePooledClient(listeningHost string, listeningPort int) *GoroutinePooledClient
NewGoroutinePooledClient instantiates an instance of GoroutinePooledClient, which is used to listen on the listening port to receive subscription info. When listeningHost is "", the default host is the local address. When listeningPort is 0, enable the reverse stream subscription.
func (*GoroutinePooledClient) Close ¶
func (t *GoroutinePooledClient) Close()
Close closes the client and stop subscribing.
func (*GoroutinePooledClient) IsClosed ¶
func (t *GoroutinePooledClient) IsClosed() bool
IsClosed checks whether the client is closed.
func (*GoroutinePooledClient) Subscribe ¶
func (t *GoroutinePooledClient) Subscribe(req *SubscribeRequest) error
Subscribe helps you to subscribe the specific action of the table according to the req.
func (*GoroutinePooledClient) UnSubscribe ¶
func (t *GoroutinePooledClient) UnSubscribe(req *SubscribeRequest) error
UnSubscribe helps you to unsubscribe the specific action of the table according to the req.
type IMessage ¶
type IMessage interface {
// GetTopic returns the topic in string format.
GetTopic() string
GetSym() string
// GetOffset returns the offset of the subscription messages.
GetOffset() int64
// GetValue returns the value of the subscription messages based on the column index of the subscribed table.
GetValue(index int) model.DataForm
// GetValueByName returns the value of the subscription messages based on the column name of the subscribed table.
GetValueByName(name string) model.DataForm
// Size returns the rows of the subscription messages.
Size() int
}
IMessage is the interface of subscription messages.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is the implementation of the IMessage.
func (*Message) GetValue ¶
GetValue returns the value of the subscription message based on the column index of the subscribed table.
func (*Message) GetValueByName ¶
GetValueByName returns the value of the subscription message based on the column name of the subscribed table.
type MessageBatchHandler ¶
type MessageBatchHandler interface {
// DoEvent will be called when you subscribe with a goroutineClient or a goroutinePooledClient
DoEvent(msg []IMessage)
}
MessageBatchHandler is an interface which will help you to handle message. You can implement the interface and use it when instantiate a SubscribeRequest or use DefaultMessageBatchHandler by default.
type MessageHandler ¶
type MessageHandler interface {
// DoEvent will be called when you subscribe with a goroutineClient or a goroutinePooledClient
DoEvent(msg IMessage)
}
MessageHandler is an interface which will help you to handle message. You can implement the interface and use it when instantiate a SubscribeRequest or use DefaultMessageHandler by default.
type PollingClient ¶
type PollingClient struct {
// contains filtered or unexported fields
}
PollingClient is a client for streaming subscription, which allows you to get subscription from the topicPoller.
func NewPollingClient ¶
func NewPollingClient(listeningHost string, listeningPort int) *PollingClient
NewPollingClient instantiates a new polling client and listens on the listening port to get subscription. When listeningHost is "", the default host is the local address. When listeningPort is 0, enable the reverse stream subscription.
func (*PollingClient) IsClosed ¶
func (t *PollingClient) IsClosed() bool
IsClosed checks whether the client is closed.
func (*PollingClient) Subscribe ¶
func (t *PollingClient) Subscribe(req *SubscribeRequest) (*TopicPoller, error)
Subscribe helps you to subscribe the specific action of the table according to the req.
func (*PollingClient) UnSubscribe ¶
func (t *PollingClient) UnSubscribe(req *SubscribeRequest) error
UnSubscribe helps you to unsubscribe the specific action of the table according to the req.
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a ring buffer for common types. It never is full and always grows if it will be full. It is not thread-safe(goroutine-safe) so you must use the lock-like synchronization primitive to use it in multiple writers and multiple readers.
func NewRingBuffer ¶
func NewRingBuffer(initialSize int) *RingBuffer
func (*RingBuffer) Capacity ¶
func (r *RingBuffer) Capacity() int
Capacity returns the size of the underlying buffer.
func (*RingBuffer) IsEmpty ¶
func (r *RingBuffer) IsEmpty() bool
func (*RingBuffer) Len ¶
func (r *RingBuffer) Len() int
func (*RingBuffer) Peek ¶
func (r *RingBuffer) Peek() T
func (*RingBuffer) Pop ¶
func (r *RingBuffer) Pop() T
func (*RingBuffer) Read ¶
func (r *RingBuffer) Read() (T, error)
func (*RingBuffer) Reset ¶
func (r *RingBuffer) Reset()
func (*RingBuffer) Write ¶
func (r *RingBuffer) Write(v T)
type StreamDeserializer ¶
type StreamDeserializer struct {
// contains filtered or unexported fields
}
func NewStreamDeserializer ¶
func NewStreamDeserializer(opt *StreamDeserializerOption) (*StreamDeserializer, error)
type SubscribeRequest ¶
type SubscribeRequest struct {
// Server address
Address string
// the user ID
UserID string
// password of the user
Password string
// Name of the table to be subscribed
TableName string
// Name of the subscription task
ActionName string
// If treat data as table
MsgAsTable bool
// Offset of subscription
Offset int64
// When AllowExists=true, if the topic already exists before subscribing,
// the server will not throw an exception.
AllowExists bool
// The amount of data processed at one time
BatchSize *int
// timeout. unit: second
Throttle *float32
// whether to allow reconnection
Reconnect bool
// Specify parameter Filter with function setStreamTableFilterColumn.
// SetStreamTableFilterColumn specifies the filtering column of a stream table.
// Only the messages with filtering column values in filter are subscribed.
Filter *model.Vector
// handle subscription information, batchSize must be -1
Handler MessageHandler
// batch handle subscription information, batchSize must >= 1
BatchHandler MessageBatchHandler
// StreamDeserializer to decode heterogenous streaming
MsgDeserializer *StreamDeserializer
// if enable SCRAM verify
EnableScram bool
// contains filtered or unexported fields
}
SubscribeRequest is used for subscribing.
func (*SubscribeRequest) SetBatchSize ¶
func (s *SubscribeRequest) SetBatchSize(bs int) *SubscribeRequest
SetBatchSize sets the batch size.
func (*SubscribeRequest) SetThrottle ¶
func (s *SubscribeRequest) SetThrottle(th float32) *SubscribeRequest
SetThrottleFloat sets the throttle.
type T ¶
type T interface{}
T defines interface{}, and will be used for generic type after go 1.18 is released.
type TableMessage ¶
type TableMessage struct {
// contains filtered or unexported fields
}
func (*TableMessage) GetOffset ¶
func (m *TableMessage) GetOffset() int64
GetOffset returns the offset of the subscription TableMessages.
func (*TableMessage) GetSym ¶
func (m *TableMessage) GetSym() string
GetTopic returns the topic in string format.
func (*TableMessage) GetTopic ¶
func (m *TableMessage) GetTopic() string
GetTopic returns the topic in string format.
func (*TableMessage) GetValue ¶
func (m *TableMessage) GetValue(index int) model.DataForm
GetValue returns the value of the subscription TableMessage based on the column index of the subscribed table.
func (*TableMessage) GetValueByName ¶
func (m *TableMessage) GetValueByName(name string) model.DataForm
GetValueByName returns the value of the subscription TableMessage based on the column name of the subscribed table.
func (*TableMessage) Size ¶
func (m *TableMessage) Size() int
Size returns the rows of the subscription TableMessages.
type TopicPoller ¶
type TopicPoller struct {
MsgDeserializer *StreamDeserializer
// contains filtered or unexported fields
}
TopicPoller is used to take one or more subscription info for polling client.
func (*TopicPoller) Poll ¶
func (t *TopicPoller) Poll(timeout, size int) []IMessage
Poll retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.
func (*TopicPoller) Take ¶
func (t *TopicPoller) Take() IMessage
Take retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
type UnboundedChan ¶
type UnboundedChan struct {
In chan<- T // channel for write
Out <-chan T // channel for read
// contains filtered or unexported fields
}
UnboundedChan is an unbounded chan. In is used to write without blocking, which supports multiple writers. and Out is used to read, which supports multiple readers. You can close the in channel if you want.
func NewUnboundedChan ¶
func NewUnboundedChan(initCapacity int) *UnboundedChan
NewUnboundedChan creates the unbounded chan. in is used to write without blocking, which supports multiple writers. and out is used to read, which supports multiple readers. You can close the in channel if you want.
func NewUnboundedChanSize ¶
func NewUnboundedChanSize(initInCapacity, initOutCapacity, initBufCapacity int) *UnboundedChan
NewUnboundedChanSize is like NewUnboundedChan but you can set initial capacity for In, Out, Buffer.
func (UnboundedChan) BufLen ¶
func (c UnboundedChan) BufLen() int
BufLen returns len of the buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.
func (UnboundedChan) IsClosed ¶
func (c UnboundedChan) IsClosed() bool
func (UnboundedChan) Len ¶
func (c UnboundedChan) Len() int
Len returns len of In plus len of Out plus len of buffer. It is not accurate and only for your evaluating approximate number of elements in this chan, see https://github.com/smallnest/chanx/issues/7.
Source Files
¶
- abstract_client.go
- basic_message.go
- deserializer.go
- goroutine_client.go
- goroutine_pooled_client.go
- handler_looper.go
- listening.go
- message_batch_handler.go
- message_handler.go
- message_parser.go
- polling_client.go
- reconnect_detector.go
- reconnect_item.go
- ringBuffer.go
- stream_deserializer.go
- subscriber.go
- topic_poller.go
- unboundedChan.go
- util.go
- var.go