subscription

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package subscription is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientNotExists = errors.New("client not exists")
)

Functions

func FromTopic

func FromTopic(topic packets.Topic, id uint32) *gmqtt.Subscription

FromTopic returns the subscription instance for given topic and subscription id.

func GetClientSubscriptions

func GetClientSubscriptions(store Store, clientID string, t IterationType) []*gmqtt.Subscription

GetClientSubscriptions returns the subscriptions of a specific client.

func GetFullTopicName

func GetFullTopicName(shareName, topicFilter string) string

GetFullTopicName returns the full topic name of given shareName and topicFilter

func SplitTopic

func SplitTopic(topic string) (shareName, topicFilter string)

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][]*gmqtt.Subscription

ClientSubscriptions groups the subscriptions by client id.

func Get

func Get(store Store, topicFilter string, t IterationType) ClientSubscriptions

Get returns the subscriptions that equals the passed topic filter.

func GetTopicMatched

func GetTopicMatched(store Store, topicFilter string, t IterationType) ClientSubscriptions

GetTopicMatched returns the subscriptions that match the passed topic.

type IterateFn

type IterateFn func(clientID string, sub *gmqtt.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
}

IterationOptions

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
	// TypeSYS represents shared topic, which start with '$share/'.
	TypeShared
	// TypeNonShared represents non-shared topic.
	TypeNonShared
	TypeAll = TypeSYS | TypeShared | TypeNonShared
)

type MatchType

type MatchType byte

MatchType specifies what match operation will be performed during the iteration.

const (
	MatchName MatchType = 1 << iota
	MatchFilter
)

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

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) Close

func (m *MockStore) Close() error

Close mocks base method

func (*MockStore) EXPECT

func (m *MockStore) EXPECT() *MockStoreMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStore) GetClientStats

func (m *MockStore) GetClientStats(clientID string) (Stats, error)

GetClientStats mocks base method

func (*MockStore) GetStats

func (m *MockStore) GetStats() Stats

GetStats mocks base method

func (*MockStore) Init

func (m *MockStore) Init(clientIDs []string) error

Init 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

func (m *MockStore) Unsubscribe(clientID string, topics ...string) error

Unsubscribe mocks base method

func (*MockStore) UnsubscribeAll

func (m *MockStore) UnsubscribeAll(clientID string) error

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(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(clientID string, subscriptions ...*gmqtt.Subscription) (rs SubscribeResult, err error)
	// Unsubscribe removes subscriptions of a specific client.
	Unsubscribe(clientID string, topics ...string) error
	// UnsubscribeAll removes all subscriptions of a specific client.
	UnsubscribeAll(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(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 *gmqtt.Subscription
	// AlreadyExisted shows whether the topic is already existed.
	AlreadyExisted bool
}

SubscribeResult is the result of Subscribe()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL