Documentation ¶
Overview ¶
Package subscription is a generated GoMock package.
Index ¶
- Variables
- func FromTopic(topic packet.Topic, id uint32) *subscription.Subscription
- func GetClientSubscriptions(ctx context.Context, store Store, clientID string, t IterationType) []*subscription.Subscription
- func GetFullTopicName(shareName, topicFilter string) string
- func SplitTopic(topic string) (shareName, topicFilter string)
- type ClientSubscriptions
- type IterateFn
- type IterationOptions
- type IterationType
- type MatchType
- type MockStatsReader
- type MockStatsReaderMockRecorder
- type MockStore
- func (m *MockStore) Close() error
- func (m *MockStore) EXPECT() *MockStoreMockRecorder
- func (m *MockStore) GetClientStats(clientID string) (Stats, error)
- func (m *MockStore) GetStats() Stats
- func (m *MockStore) Init(clientIDs []string) error
- func (m *MockStore) Iterate(fn IterateFn, options IterationOptions)
- func (m *MockStore) Subscribe(clientID string, subscriptions ...*gmqtt.Subscription) (SubscribeResult, error)
- func (m *MockStore) Unsubscribe(clientID string, topics ...string) error
- func (m *MockStore) UnsubscribeAll(clientID string) error
- type MockStoreMockRecorder
- func (mr *MockStoreMockRecorder) Close() *gomock.Call
- func (mr *MockStoreMockRecorder) GetClientStats(clientID interface{}) *gomock.Call
- func (mr *MockStoreMockRecorder) GetStats() *gomock.Call
- func (mr *MockStoreMockRecorder) Init(clientIDs interface{}) *gomock.Call
- func (mr *MockStoreMockRecorder) Iterate(fn, options interface{}) *gomock.Call
- func (mr *MockStoreMockRecorder) Subscribe(clientID interface{}, subscriptions ...interface{}) *gomock.Call
- func (mr *MockStoreMockRecorder) Unsubscribe(clientID interface{}, topics ...interface{}) *gomock.Call
- func (mr *MockStoreMockRecorder) UnsubscribeAll(clientID interface{}) *gomock.Call
- type NewStore
- type Stats
- type StatsReader
- type Store
- type SubscribeResult
Constants ¶
This section is empty.
Variables ¶
var (
ErrClientNotExists = errors.New("client not exists")
)
Functions ¶
func FromTopic ¶
func FromTopic(topic packet.Topic, id uint32) *subscription.Subscription
FromTopic returns the subscription instance for given topic and subscription id.
func GetClientSubscriptions ¶
func GetClientSubscriptions(ctx context.Context, store Store, clientID string, t IterationType) []*subscription.Subscription
GetClientSubscriptions returns the subscriptions of a specific client.
func GetFullTopicName ¶
GetFullTopicName returns the full topic name of given shareName and topicFilter
func SplitTopic ¶
SplitTopic returns the shareName and topicFilter of the given topic. If the topic is invalid, returns empty strings.
Types ¶
type ClientSubscriptions ¶
type ClientSubscriptions map[string][]*subscription.Subscription
ClientSubscriptions groups the subscriptions by client id.
func Get ¶
func Get(ctx context.Context, store Store, topicFilter string, t IterationType) ClientSubscriptions
Get returns the subscriptions that equals the passed topic filter.
func GetTopicMatched ¶
func GetTopicMatched(ctx context.Context, store Store, topicFilter string, t IterationType) ClientSubscriptions
GetTopicMatched returns the subscriptions that match the passed topic.
type IterateFn ¶
type IterateFn func(clientID string, sub *subscription.Subscription) bool
IterateFn is the callback function used by iterate() Return false means to stop the iteration.
type IterationOptions ¶
type IterationOptions struct { // Type specifies the types of subscription that will be iterated. // For example, if Type = TypeShared | TypeNonShared , then all shared and non-shared subscriptions will be iterated Type IterationType // ClientID specifies the subscriber client id. ClientID string // TopicName represents topic filter or topic name. This field works together with MatchType. TopicName string // MatchType specifies the matching type of the iteration. // if MatchName, the IterateFn will be called when the subscription topic filter is equal to TopicName. // if MatchTopic, the IterateFn will be called when the TopicName match the subscription topic filter. MatchType MatchType }
type IterationType ¶
type IterationType byte
IterationType specifies the types of subscription that will be iterated.
const ( // TypeSYS represents system topic, which start with '$'. TypeSYS IterationType = 1 << iota TypeShared // TypeNonShared represents non-shared topic. TypeAll = TypeSYS | TypeShared | TypeNonShared )
type MatchType ¶
type MatchType byte
MatchType specifies what match operation will be performed during the iteration.
type MockStatsReader ¶
type MockStatsReader struct {
// contains filtered or unexported fields
}
MockStatsReader is a mock of StatsReader interface
func NewMockStatsReader ¶
func NewMockStatsReader(ctrl *gomock.Controller) *MockStatsReader
NewMockStatsReader creates a new mock instance
func (*MockStatsReader) EXPECT ¶
func (m *MockStatsReader) EXPECT() *MockStatsReaderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockStatsReader) GetClientStats ¶
func (m *MockStatsReader) GetClientStats(clientID string) (Stats, error)
GetClientStats mocks base method
func (*MockStatsReader) GetStats ¶
func (m *MockStatsReader) GetStats() Stats
GetStats mocks base method
type MockStatsReaderMockRecorder ¶
type MockStatsReaderMockRecorder struct {
// contains filtered or unexported fields
}
MockStatsReaderMockRecorder is the mock recorder for MockStatsReader
func (*MockStatsReaderMockRecorder) GetClientStats ¶
func (mr *MockStatsReaderMockRecorder) GetClientStats(clientID interface{}) *gomock.Call
GetClientStats indicates an expected call of GetClientStats
func (*MockStatsReaderMockRecorder) GetStats ¶
func (mr *MockStatsReaderMockRecorder) GetStats() *gomock.Call
GetStats indicates an expected call of GetStats
type MockStore ¶
type MockStore struct {
// contains filtered or unexported fields
}
MockStore is a mock of Store interface
func NewMockStore ¶
func NewMockStore(ctrl *gomock.Controller) *MockStore
NewMockStore creates a new mock instance
func (*MockStore) EXPECT ¶
func (m *MockStore) EXPECT() *MockStoreMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockStore) GetClientStats ¶
GetClientStats mocks base method
func (*MockStore) Iterate ¶
func (m *MockStore) Iterate(fn IterateFn, options IterationOptions)
Iterate mocks base method
func (*MockStore) Subscribe ¶
func (m *MockStore) Subscribe(clientID string, subscriptions ...*gmqtt.Subscription) (SubscribeResult, error)
Subscribe mocks base method
func (*MockStore) Unsubscribe ¶
Unsubscribe mocks base method
func (*MockStore) UnsubscribeAll ¶
UnsubscribeAll mocks base method
type MockStoreMockRecorder ¶
type MockStoreMockRecorder struct {
// contains filtered or unexported fields
}
MockStoreMockRecorder is the mock recorder for MockStore
func (*MockStoreMockRecorder) Close ¶
func (mr *MockStoreMockRecorder) Close() *gomock.Call
Close indicates an expected call of Close
func (*MockStoreMockRecorder) GetClientStats ¶
func (mr *MockStoreMockRecorder) GetClientStats(clientID interface{}) *gomock.Call
GetClientStats indicates an expected call of GetClientStats
func (*MockStoreMockRecorder) GetStats ¶
func (mr *MockStoreMockRecorder) GetStats() *gomock.Call
GetStats indicates an expected call of GetStats
func (*MockStoreMockRecorder) Init ¶
func (mr *MockStoreMockRecorder) Init(clientIDs interface{}) *gomock.Call
Init indicates an expected call of Init
func (*MockStoreMockRecorder) Iterate ¶
func (mr *MockStoreMockRecorder) Iterate(fn, options interface{}) *gomock.Call
Iterate indicates an expected call of Iterate
func (*MockStoreMockRecorder) Subscribe ¶
func (mr *MockStoreMockRecorder) Subscribe(clientID interface{}, subscriptions ...interface{}) *gomock.Call
Subscribe indicates an expected call of Subscribe
func (*MockStoreMockRecorder) Unsubscribe ¶
func (mr *MockStoreMockRecorder) Unsubscribe(clientID interface{}, topics ...interface{}) *gomock.Call
Unsubscribe indicates an expected call of Unsubscribe
func (*MockStoreMockRecorder) UnsubscribeAll ¶
func (mr *MockStoreMockRecorder) UnsubscribeAll(clientID interface{}) *gomock.Call
UnsubscribeAll indicates an expected call of UnsubscribeAll
type Stats ¶
type Stats struct { // SubscriptionsTotal shows how many subscription has been added to the store. // Duplicated subscription is not counting. SubscriptionsTotal uint64 // SubscriptionsCurrent shows the current subscription number in the store. SubscriptionsCurrent uint64 }
Stats is the statistics information of the store
type StatsReader ¶
type StatsReader interface { // GetStats return the global stats. GetStats() Stats // GetClientStats return the stats of a specific client. // If stats not exists, return an error. GetClientStats(clientID string) (Stats, error) }
StatsReader provides the ability to get statistics information.
type Store ¶
type Store interface { // Init will be called only once after the server start, the implementation should load the subscriptions of the given clients into memory. Init(ctx context.Context, clientIDs []string) error // Subscribe adds subscriptions to a specific client. // Notice: // This method will succeed even if the client is not exists, the subscriptions // will affect the new client with the client id. Subscribe(ctx context.Context, clientID string, subscriptions ...*subscription.Subscription) (rs SubscribeResult, err error) // Unsubscribe removes subscriptions of a specific client. Unsubscribe(ctx context.Context, clientID string, topics ...string) error // UnsubscribeAll removes all subscriptions of a specific client. UnsubscribeAll(ctx context.Context, clientID string) error // Iterate iterates all subscriptions. The callback is called once for each subscription. // If callback return false, the iteration will be stopped. // Notice: // The results are not sorted in any way, no ordering of any kind is guaranteed. // This method will walk through all subscriptions, // so it is a very expensive operation. Do not call it frequently. Iterate(ctx context.Context, fn IterateFn, options IterationOptions) Close() error StatsReader }
Store is the interface used by gmqtt.server to handler the operations of subscriptions. This interface provides the ability for extensions to interact with the subscriptions. Notice: This methods will not trigger any gmqtt hooks.
type SubscribeResult ¶
type SubscribeResult = []struct { // Topic is the Subscribed topic Subscription *subscription.Subscription // AlreadyExisted shows whether the topic is already existed. AlreadyExisted bool }
SubscribeResult is the result of Subscribe()