realtime

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const BrokerModeEmbedded = "embedded"
View Source
const BrokerModeExternal = "external"
View Source
const TypeWS = "ws"

Variables

View Source
var (
	// ErrInvalidMessage indicates that a message payload was not valid.
	ErrInvalidMessage = errors.New("message type not binary")
)
View Source
var ErrInvalidTopicRegistrationArgs = errors.New("realtime: invalid topic registration args")
View Source
var ErrTopicClientDisconnectedByHandler = errors.New("realtime: client disconnected by topic handler")
View Source
var ErrTopicClientRejectedByHandler = errors.New("realtime: client rejected by topic handler")
View Source
var ErrTopicCtxNoClient = errors.New("realtime: topic context has no client")
View Source
var ErrTopicCtxNoPublisher = errors.New("realtime: topic context has no publisher")
View Source
var ErrTopicCtxSessionControlUnsupported = errors.New("realtime: session control is unsupported")
View Source
var ErrTopicHandlerPanic = errors.New("realtime: panic in topic handler")
View Source
var ErrTopicHandlerTimeout = errors.New("realtime: topic handler timed out")
View Source
var ErrTopicNotAllowed = errors.New("realtime: topic is not allowed by acl")
View Source
var ErrTopicRegistrarStopped = errors.New("realtime: topic registrar is stopped")
View Source
var HooksGroupName = "mqtt_hooks"
View Source
var ListenersGroupName = "mqtt_listeners"
View Source
var SubscribersGroupName = "mqtt_subscribers"
View Source
var TopicMiddlewaresGroupName = "mqtt_topic_middlewares"

Functions

func AppendHooks

func AppendHooks(ms usmqtt.Broker, hooks ...mqtt.Hook) error

func AppendListeners

func AppendListeners(ms usmqtt.Broker, listeners ...listeners.Listener) error

func ConnectedContext added in v1.9.0

func ConnectedContext(ctx context.Context) (context.Context, bool)

func Init added in v1.12.0

func Init() di.Node

func Module

func Module(opts ...di.Node) di.Node

func NewBroker added in v1.10.0

func NewBroker(cfg Config, embedServer *usmqtt.Server) (usmqtt.Broker, error)

func RegisterBrokerLifecycle added in v1.10.0

func RegisterBrokerLifecycle(lc fx.Lifecycle, broker usmqtt.Broker)

func SetupTopicMiddlewares added in v1.9.0

func SetupTopicMiddlewares(in setupTopicMiddlewaresIn)

func SetupTopicSubscribers added in v1.9.0

func SetupTopicSubscribers(in setupTopicSubscribersIn) error

func UseAllowHook added in v1.4.0

func UseAllowHook() di.Node

func UseTCPListener added in v1.8.0

func UseTCPListener() di.Node

func UseWebsocketListener added in v1.4.0

func UseWebsocketListener(opts ...Option) di.Node

func WithClaims added in v1.9.0

func WithClaims(ctx context.Context, claims Claims) context.Context

func WithClientIdentity added in v1.9.0

func WithClientIdentity(ctx context.Context, identity ClientIdentity) context.Context

func WithConnectedContext added in v1.9.0

func WithConnectedContext(ctx context.Context, connected context.Context) context.Context

Types

type Authorizer

type Authorizer interface {
	Authorize() fiber.Handler
}

func NewAuthorizer

func NewAuthorizer(logger *zap.Logger) Authorizer

type BrokerConfig added in v1.10.0

type BrokerConfig struct {
	Mode           string          `mapstructure:"mode" default:"embedded"`
	Endpoint       string          `mapstructure:"endpoint"`
	ClientID       string          `mapstructure:"client_id"`
	Username       string          `mapstructure:"username"`
	Password       string          `mapstructure:"password"`
	CleanSession   bool            `mapstructure:"clean_session" default:"false"`
	ConnectTimeout time.Duration   `mapstructure:"connect_timeout" default:"10s"`
	TLS            BrokerTLSConfig `mapstructure:"tls"`
}

type BrokerTLSConfig added in v1.10.0

type BrokerTLSConfig struct {
	CAFile             string `mapstructure:"ca_file"`
	CertFile           string `mapstructure:"cert_file"`
	KeyFile            string `mapstructure:"key_file"`
	ServerName         string `mapstructure:"server_name"`
	InsecureSkipVerify bool   `mapstructure:"insecure_skip_verify"`
}

func (BrokerTLSConfig) IsZero added in v1.10.0

func (c BrokerTLSConfig) IsZero() bool

func (BrokerTLSConfig) Load added in v1.10.0

func (c BrokerTLSConfig) Load() (*tls.Config, error)

type Claims added in v1.9.0

type Claims map[string]any

func ClaimsFromContext added in v1.9.0

func ClaimsFromContext(ctx context.Context) (Claims, bool)

type ClientConnectContextHook added in v1.9.0

type ClientConnectContextHook struct {
	mqtt.HookBase
	// contains filtered or unexported fields
}

func NewClientConnectContextHook added in v1.9.0

func NewClientConnectContextHook(in newClientConnectContextHookIn) *ClientConnectContextHook

func (*ClientConnectContextHook) ID added in v1.9.0

func (*ClientConnectContextHook) OnConnect added in v1.9.0

func (h *ClientConnectContextHook) OnConnect(cl *mqtt.Client, pk packets.Packet) error

func (*ClientConnectContextHook) OnDisconnect added in v1.9.0

func (h *ClientConnectContextHook) OnDisconnect(cl *mqtt.Client, _ error, _ bool)

func (*ClientConnectContextHook) Provides added in v1.9.0

func (h *ClientConnectContextHook) Provides(b byte) bool

type ClientConnectContextStore added in v1.9.0

type ClientConnectContextStore struct {
	// contains filtered or unexported fields
}

func NewClientConnectContextStore added in v1.9.0

func NewClientConnectContextStore() *ClientConnectContextStore

func (*ClientConnectContextStore) Delete added in v1.9.0

func (s *ClientConnectContextStore) Delete(clientID string)

func (*ClientConnectContextStore) Get added in v1.9.0

func (s *ClientConnectContextStore) Get(clientID string) (context.Context, bool)

func (*ClientConnectContextStore) Set added in v1.9.0

func (s *ClientConnectContextStore) Set(clientID string, ctx context.Context)

type ClientIdentity added in v1.9.0

type ClientIdentity struct {
	ClientID string
	Username string
}

func IdentityFromContext added in v1.9.0

func IdentityFromContext(ctx context.Context) (ClientIdentity, bool)

type ClientIdentityHook added in v1.9.0

type ClientIdentityHook struct {
	mqtt.HookBase
	// contains filtered or unexported fields
}

func NewClientIdentityHook added in v1.9.0

func NewClientIdentityHook(store *ClientIdentityStore) *ClientIdentityHook

func (*ClientIdentityHook) ID added in v1.9.0

func (h *ClientIdentityHook) ID() string

func (*ClientIdentityHook) OnConnect added in v1.9.0

func (h *ClientIdentityHook) OnConnect(cl *mqtt.Client, pk packets.Packet) error

func (*ClientIdentityHook) OnDisconnect added in v1.9.0

func (h *ClientIdentityHook) OnDisconnect(cl *mqtt.Client, _ error, _ bool)

func (*ClientIdentityHook) Provides added in v1.9.0

func (h *ClientIdentityHook) Provides(b byte) bool

type ClientIdentityStore added in v1.9.0

type ClientIdentityStore struct {
	// contains filtered or unexported fields
}

func NewClientIdentityStore added in v1.9.0

func NewClientIdentityStore() *ClientIdentityStore

func (*ClientIdentityStore) Delete added in v1.9.0

func (s *ClientIdentityStore) Delete(clientID string)

func (*ClientIdentityStore) Get added in v1.9.0

func (s *ClientIdentityStore) Get(clientID string) (ClientIdentity, bool)

func (*ClientIdentityStore) Set added in v1.9.0

func (s *ClientIdentityStore) Set(clientID string, identity ClientIdentity)

type Config added in v1.8.0

type Config struct {
	Broker            BrokerConfig            `mapstructure:"broker"`
	SessionControl    SessionControlConfig    `mapstructure:"session_control"`
	TCPListener       TCPListenerConfig       `mapstructure:"tcp_listener"`
	WebsocketListener WebsocketListenerConfig `mapstructure:"websocket_listener"`
	TopicACL          TopicACLConfig          `mapstructure:"topic_acl"`
}

type ConnectContextFactory added in v1.9.0

type ConnectContextFactory interface {
	BuildConnectContext(cl *mqtt.Client, pk packets.Packet) context.Context
}

type Ctx added in v1.9.0

type Ctx interface {
	context.Context

	// Client returns the underlying MQTT client.
	// Example: client := ctx.Client()
	Client() *mqtt.Client
	// ClientID returns the MQTT client identifier.
	// Example: id := ctx.ClientID()
	ClientID() string
	// Username returns the authenticated username when available.
	// Example: user := ctx.Username()
	Username() string
	// Subscription returns the matched subscription for this handler invocation.
	// Example: sub := ctx.Subscription()
	Subscription() packets.Subscription
	// Packet returns the raw MQTT packet associated with this invocation.
	// Example: pk := ctx.Packet()
	Packet() packets.Packet
	// Filter returns the matched topic filter from the subscription.
	// Example: filter := ctx.Filter()
	Filter() string
	// Topic returns the packet topic name.
	// Example: topic := ctx.Topic()
	Topic() string
	// Payload returns the raw packet payload bytes.
	// Example: payload := ctx.Payload()
	Payload() []byte
	// DecodeJSON unmarshals the payload as JSON into v.
	// Example: err := ctx.DecodeJSON(&dst)
	DecodeJSON(v any) error
	// Publish sends raw payload bytes to topic.
	// Example: err := ctx.Publish("devices/ack", []byte("ok"), false, 1)
	Publish(topic string, payload []byte, retain bool, qos byte) error
	// PublishJSON marshals payload as JSON and publishes it to topic.
	// Example: err := ctx.PublishJSON("devices/ack", map[string]any{"ok": true}, false, 1)
	PublishJSON(topic string, payload any, retain bool, qos byte) error
	// PublishString publishes a string payload to topic.
	// Example: err := ctx.PublishString("devices/ack", "ok", false, 1)
	PublishString(topic string, payload string, retain bool, qos byte) error
	// Context returns the current base context used by the Ctx implementation.
	// Example: base := ctx.Context()
	Context() context.Context
	// SetContext replaces the base context used by this Ctx.
	// Example: ctx.SetContext(context.WithValue(ctx.Context(), key, value))
	SetContext(ctx context.Context)
	// Identity returns client identity from context when present.
	// Example: identity, ok := ctx.Identity()
	Identity() (ClientIdentity, bool)
	// Disconnect stops the underlying client connection.
	// Example: err := ctx.Disconnect()
	Disconnect() error
	// Reject stops the client and records a rejection reason.
	// Example: err := ctx.Reject("unauthorized topic")
	Reject(reason string) error
}

Ctx provides per-message topic handler context, including MQTT metadata, payload helpers, publishing helpers, and an overridable base context.

type ManagedPubSub added in v1.9.0

type ManagedPubSub struct {
	// contains filtered or unexported fields
}

func NewManagedPubSub added in v1.9.0

func NewManagedPubSub(in newManagedPubSubIn) (*ManagedPubSub, error)

func (*ManagedPubSub) Stop added in v1.9.0

func (*ManagedPubSub) Topic added in v1.9.0

func (m *ManagedPubSub) Topic(filter string, args ...any) error

func (*ManagedPubSub) Use added in v1.9.0

func (m *ManagedPubSub) Use(middlewares ...TopicMiddleware)

type MockAuthorizer added in v1.2.0

type MockAuthorizer struct {
	mock.Mock
}

MockAuthorizer is an autogenerated mock type for the Authorizer type

func NewMockAuthorizer added in v1.2.0

func NewMockAuthorizer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAuthorizer

NewMockAuthorizer creates a new instance of MockAuthorizer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAuthorizer) Authorize added in v1.2.0

func (_mock *MockAuthorizer) Authorize() fiber.Handler

Authorize provides a mock function for the type MockAuthorizer

func (*MockAuthorizer) EXPECT added in v1.2.0

type MockAuthorizer_Authorize_Call added in v1.2.0

type MockAuthorizer_Authorize_Call struct {
	*mock.Call
}

MockAuthorizer_Authorize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authorize'

func (*MockAuthorizer_Authorize_Call) Return added in v1.2.0

func (*MockAuthorizer_Authorize_Call) Run added in v1.2.0

func (*MockAuthorizer_Authorize_Call) RunAndReturn added in v1.2.0

type MockAuthorizer_Expecter added in v1.2.0

type MockAuthorizer_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockAuthorizer_Expecter) Authorize added in v1.2.0

Authorize is a helper method to define mock.On call

type MockBroker added in v1.2.0

type MockBroker struct {
	mock.Mock
}

MockBroker is an autogenerated mock type for the Broker type

func NewMockBroker added in v1.2.0

func NewMockBroker(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockBroker

NewMockBroker creates a new instance of MockBroker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockBroker) EXPECT added in v1.2.0

func (_m *MockBroker) EXPECT() *MockBroker_Expecter

func (*MockBroker) Publish added in v1.2.0

func (_mock *MockBroker) Publish(topic string, payload []byte, retain bool, qos byte) error

Publish provides a mock function for the type MockBroker

func (*MockBroker) PublishJSON added in v1.9.0

func (_mock *MockBroker) PublishJSON(topic string, payload any, retain bool, qos byte) error

PublishJSON provides a mock function for the type MockBroker

func (*MockBroker) PublishString added in v1.9.0

func (_mock *MockBroker) PublishString(topic string, payload string, retain bool, qos byte) error

PublishString provides a mock function for the type MockBroker

func (*MockBroker) Subscribe added in v1.2.0

func (_mock *MockBroker) Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error

Subscribe provides a mock function for the type MockBroker

func (*MockBroker) Unsubscribe added in v1.2.0

func (_mock *MockBroker) Unsubscribe(filter string, subscriptionId int) error

Unsubscribe provides a mock function for the type MockBroker

type MockBroker_Expecter added in v1.2.0

type MockBroker_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockBroker_Expecter) Publish added in v1.2.0

func (_e *MockBroker_Expecter) Publish(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockBroker_Publish_Call

Publish is a helper method to define mock.On call

  • topic string
  • payload []byte
  • retain bool
  • qos byte

func (*MockBroker_Expecter) PublishJSON added in v1.9.0

func (_e *MockBroker_Expecter) PublishJSON(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockBroker_PublishJSON_Call

PublishJSON is a helper method to define mock.On call

  • topic string
  • payload any
  • retain bool
  • qos byte

func (*MockBroker_Expecter) PublishString added in v1.9.0

func (_e *MockBroker_Expecter) PublishString(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockBroker_PublishString_Call

PublishString is a helper method to define mock.On call

  • topic string
  • payload string
  • retain bool
  • qos byte

func (*MockBroker_Expecter) Subscribe added in v1.2.0

func (_e *MockBroker_Expecter) Subscribe(filter interface{}, subscriptionId interface{}, handler interface{}) *MockBroker_Subscribe_Call

Subscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int
  • handler mqtt.InlineSubFn

func (*MockBroker_Expecter) Unsubscribe added in v1.2.0

func (_e *MockBroker_Expecter) Unsubscribe(filter interface{}, subscriptionId interface{}) *MockBroker_Unsubscribe_Call

Unsubscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int

type MockBroker_PublishJSON_Call added in v1.9.0

type MockBroker_PublishJSON_Call struct {
	*mock.Call
}

MockBroker_PublishJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJSON'

func (*MockBroker_PublishJSON_Call) Return added in v1.9.0

func (*MockBroker_PublishJSON_Call) Run added in v1.9.0

func (_c *MockBroker_PublishJSON_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockBroker_PublishJSON_Call

func (*MockBroker_PublishJSON_Call) RunAndReturn added in v1.9.0

func (_c *MockBroker_PublishJSON_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockBroker_PublishJSON_Call

type MockBroker_PublishString_Call added in v1.9.0

type MockBroker_PublishString_Call struct {
	*mock.Call
}

MockBroker_PublishString_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishString'

func (*MockBroker_PublishString_Call) Return added in v1.9.0

func (*MockBroker_PublishString_Call) Run added in v1.9.0

func (_c *MockBroker_PublishString_Call) Run(run func(topic string, payload string, retain bool, qos byte)) *MockBroker_PublishString_Call

func (*MockBroker_PublishString_Call) RunAndReturn added in v1.9.0

func (_c *MockBroker_PublishString_Call) RunAndReturn(run func(topic string, payload string, retain bool, qos byte) error) *MockBroker_PublishString_Call

type MockBroker_Publish_Call added in v1.2.0

type MockBroker_Publish_Call struct {
	*mock.Call
}

MockBroker_Publish_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Publish'

func (*MockBroker_Publish_Call) Return added in v1.2.0

func (*MockBroker_Publish_Call) Run added in v1.2.0

func (_c *MockBroker_Publish_Call) Run(run func(topic string, payload []byte, retain bool, qos byte)) *MockBroker_Publish_Call

func (*MockBroker_Publish_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Publish_Call) RunAndReturn(run func(topic string, payload []byte, retain bool, qos byte) error) *MockBroker_Publish_Call

type MockBroker_Subscribe_Call added in v1.2.0

type MockBroker_Subscribe_Call struct {
	*mock.Call
}

MockBroker_Subscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subscribe'

func (*MockBroker_Subscribe_Call) Return added in v1.2.0

func (*MockBroker_Subscribe_Call) Run added in v1.2.0

func (_c *MockBroker_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockBroker_Subscribe_Call

func (*MockBroker_Subscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockBroker_Subscribe_Call

type MockBroker_Unsubscribe_Call added in v1.2.0

type MockBroker_Unsubscribe_Call struct {
	*mock.Call
}

MockBroker_Unsubscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unsubscribe'

func (*MockBroker_Unsubscribe_Call) Return added in v1.2.0

func (*MockBroker_Unsubscribe_Call) Run added in v1.2.0

func (_c *MockBroker_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockBroker_Unsubscribe_Call

func (*MockBroker_Unsubscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockBroker_Unsubscribe_Call

type MockPublisher added in v1.2.0

type MockPublisher struct {
	mock.Mock
}

MockPublisher is an autogenerated mock type for the Publisher type

func NewMockPublisher added in v1.2.0

func NewMockPublisher(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockPublisher

NewMockPublisher creates a new instance of MockPublisher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockPublisher) EXPECT added in v1.2.0

func (_m *MockPublisher) EXPECT() *MockPublisher_Expecter

func (*MockPublisher) Publish added in v1.2.0

func (_mock *MockPublisher) Publish(topic string, payload []byte, retain bool, qos byte) error

Publish provides a mock function for the type MockPublisher

func (*MockPublisher) PublishJSON added in v1.9.0

func (_mock *MockPublisher) PublishJSON(topic string, payload any, retain bool, qos byte) error

PublishJSON provides a mock function for the type MockPublisher

func (*MockPublisher) PublishString added in v1.9.0

func (_mock *MockPublisher) PublishString(topic string, payload string, retain bool, qos byte) error

PublishString provides a mock function for the type MockPublisher

type MockPublisher_Expecter added in v1.2.0

type MockPublisher_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockPublisher_Expecter) Publish added in v1.2.0

func (_e *MockPublisher_Expecter) Publish(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockPublisher_Publish_Call

Publish is a helper method to define mock.On call

  • topic string
  • payload []byte
  • retain bool
  • qos byte

func (*MockPublisher_Expecter) PublishJSON added in v1.9.0

func (_e *MockPublisher_Expecter) PublishJSON(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockPublisher_PublishJSON_Call

PublishJSON is a helper method to define mock.On call

  • topic string
  • payload any
  • retain bool
  • qos byte

func (*MockPublisher_Expecter) PublishString added in v1.9.0

func (_e *MockPublisher_Expecter) PublishString(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockPublisher_PublishString_Call

PublishString is a helper method to define mock.On call

  • topic string
  • payload string
  • retain bool
  • qos byte

type MockPublisher_PublishJSON_Call added in v1.9.0

type MockPublisher_PublishJSON_Call struct {
	*mock.Call
}

MockPublisher_PublishJSON_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishJSON'

func (*MockPublisher_PublishJSON_Call) Return added in v1.9.0

func (*MockPublisher_PublishJSON_Call) Run added in v1.9.0

func (_c *MockPublisher_PublishJSON_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockPublisher_PublishJSON_Call

func (*MockPublisher_PublishJSON_Call) RunAndReturn added in v1.9.0

func (_c *MockPublisher_PublishJSON_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockPublisher_PublishJSON_Call

type MockPublisher_PublishString_Call added in v1.9.0

type MockPublisher_PublishString_Call struct {
	*mock.Call
}

MockPublisher_PublishString_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishString'

func (*MockPublisher_PublishString_Call) Return added in v1.9.0

func (*MockPublisher_PublishString_Call) Run added in v1.9.0

func (_c *MockPublisher_PublishString_Call) Run(run func(topic string, payload string, retain bool, qos byte)) *MockPublisher_PublishString_Call

func (*MockPublisher_PublishString_Call) RunAndReturn added in v1.9.0

func (_c *MockPublisher_PublishString_Call) RunAndReturn(run func(topic string, payload string, retain bool, qos byte) error) *MockPublisher_PublishString_Call

type MockPublisher_Publish_Call added in v1.2.0

type MockPublisher_Publish_Call struct {
	*mock.Call
}

MockPublisher_Publish_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Publish'

func (*MockPublisher_Publish_Call) Return added in v1.2.0

func (*MockPublisher_Publish_Call) Run added in v1.2.0

func (_c *MockPublisher_Publish_Call) Run(run func(topic string, payload []byte, retain bool, qos byte)) *MockPublisher_Publish_Call

func (*MockPublisher_Publish_Call) RunAndReturn added in v1.2.0

func (_c *MockPublisher_Publish_Call) RunAndReturn(run func(topic string, payload []byte, retain bool, qos byte) error) *MockPublisher_Publish_Call

type MockSubscriber added in v1.2.0

type MockSubscriber struct {
	mock.Mock
}

MockSubscriber is an autogenerated mock type for the Subscriber type

func NewMockSubscriber added in v1.2.0

func NewMockSubscriber(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockSubscriber

NewMockSubscriber creates a new instance of MockSubscriber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockSubscriber) EXPECT added in v1.2.0

func (*MockSubscriber) Subscribe added in v1.2.0

func (_mock *MockSubscriber) Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error

Subscribe provides a mock function for the type MockSubscriber

func (*MockSubscriber) Unsubscribe added in v1.2.0

func (_mock *MockSubscriber) Unsubscribe(filter string, subscriptionId int) error

Unsubscribe provides a mock function for the type MockSubscriber

type MockSubscriber_Expecter added in v1.2.0

type MockSubscriber_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockSubscriber_Expecter) Subscribe added in v1.2.0

func (_e *MockSubscriber_Expecter) Subscribe(filter interface{}, subscriptionId interface{}, handler interface{}) *MockSubscriber_Subscribe_Call

Subscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int
  • handler mqtt.InlineSubFn

func (*MockSubscriber_Expecter) Unsubscribe added in v1.2.0

func (_e *MockSubscriber_Expecter) Unsubscribe(filter interface{}, subscriptionId interface{}) *MockSubscriber_Unsubscribe_Call

Unsubscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int

type MockSubscriber_Subscribe_Call added in v1.2.0

type MockSubscriber_Subscribe_Call struct {
	*mock.Call
}

MockSubscriber_Subscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subscribe'

func (*MockSubscriber_Subscribe_Call) Return added in v1.2.0

func (*MockSubscriber_Subscribe_Call) Run added in v1.2.0

func (_c *MockSubscriber_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockSubscriber_Subscribe_Call

func (*MockSubscriber_Subscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockSubscriber_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockSubscriber_Subscribe_Call

type MockSubscriber_Unsubscribe_Call added in v1.2.0

type MockSubscriber_Unsubscribe_Call struct {
	*mock.Call
}

MockSubscriber_Unsubscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unsubscribe'

func (*MockSubscriber_Unsubscribe_Call) Return added in v1.2.0

func (*MockSubscriber_Unsubscribe_Call) Run added in v1.2.0

func (_c *MockSubscriber_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockSubscriber_Unsubscribe_Call

func (*MockSubscriber_Unsubscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockSubscriber_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockSubscriber_Unsubscribe_Call

type Option added in v1.2.0

type Option func(*Websocket)

Option customizes a Websocket instance.

func WithApp added in v1.2.0

func WithApp(app fiber.Router) Option

WithApp sets the Fiber router for registering the websocket handler.

func WithAuthorizer added in v1.2.0

func WithAuthorizer(authorizer Authorizer) Option

WithAuthorizer sets the authorizer for the websocket handler.

func WithId added in v1.2.0

func WithId(id string) Option

WithId sets the Websocket listener id.

func WithPath added in v1.2.0

func WithPath(path string) Option

WithPath sets the route path for the websocket handler.

func WithUpgrader added in v1.2.0

func WithUpgrader(upgrader *websocket.Upgrader) Option

WithUpgrader sets the websocket upgrader.

type SessionControlConfig added in v1.10.0

type SessionControlConfig struct {
	Provider string                   `mapstructure:"provider"`
	EMQX     SessionControlEMQXConfig `mapstructure:"emqx"`
}

type SessionControlEMQXConfig added in v1.10.0

type SessionControlEMQXConfig struct {
	Endpoint    string          `mapstructure:"endpoint"`
	Username    string          `mapstructure:"username"`
	Password    string          `mapstructure:"password"`
	BearerToken string          `mapstructure:"bearer_token"`
	Timeout     time.Duration   `mapstructure:"timeout" default:"5s"`
	TLS         BrokerTLSConfig `mapstructure:"tls"`
}

type TCPListenerConfig added in v1.8.0

type TCPListenerConfig struct {
	ID      string `mapstructure:"id" default:"t1"`
	Address string `mapstructure:"address" default:":1883"`
}

type TimeoutTopicMiddlewareOption added in v1.9.0

type TimeoutTopicMiddlewareOption func(*timeoutTopicMiddlewareConfig)

func WithTimeoutDisconnect added in v1.9.0

func WithTimeoutDisconnect() TimeoutTopicMiddlewareOption

type TopicACLConfig added in v1.9.0

type TopicACLConfig struct {
	Enabled         bool     `mapstructure:"enabled" default:"false"`
	AllowedPrefixes []string `mapstructure:"allowed_prefixes"`
}

type TopicHandler added in v1.9.0

type TopicHandler func(ctx Ctx) error

type TopicMiddleware added in v1.9.0

type TopicMiddleware func(next TopicHandler) TopicHandler

func RecoverTopicMiddleware added in v1.9.0

func RecoverTopicMiddleware(log *zap.Logger) TopicMiddleware

func TimeoutTopicMiddleware added in v1.9.0

func TimeoutTopicMiddleware(timeout time.Duration, opts ...TimeoutTopicMiddlewareOption) TopicMiddleware

func UseClientIdentityContext added in v1.9.0

func UseClientIdentityContext(store *ClientIdentityStore) TopicMiddleware

func UseConnectedContext added in v1.9.0

func UseConnectedContext(store *ClientConnectContextStore) TopicMiddleware

type TopicRegistrar added in v1.9.0

type TopicRegistrar interface {
	Use(middlewares ...TopicMiddleware)
	Topic(filter string, args ...any) error
}

type Websocket

type Websocket struct {
	sync.RWMutex
	Id          string       // the internal id of the listener
	App         fiber.Router // the fiber router to register the websocket handler on
	Authorizer  Authorizer
	Path        string
	Log         *slog.Logger          // server logging
	EstablishFn listeners.EstablishFn // the server's establish connection handler
	Upgrader    *websocket.Upgrader   //  upgrade the incoming http/tcp connection to a websocket compliant connection.
}

Websocket is a listener for establishing websocket connections.

func NewWebsocket

func NewWebsocket(app fiber.Router, authorizer Authorizer) *Websocket

NewWebsocket initializes and returns a new Websocket listener, listening on an address.

func NewWebsocketWithOptions added in v1.2.0

func NewWebsocketWithOptions(opts ...Option) *Websocket

NewWebsocketWithOptions initializes a Websocket with defaults and applies options.

func (*Websocket) Address

func (l *Websocket) Address() string

Address returns the address of the listener.

func (*Websocket) Close

func (l *Websocket) Close(closeClients listeners.CloseFn)

Close closes the listener and any client connections.

func (*Websocket) Handle

func (l *Websocket) Handle(r fiber.Router)

func (*Websocket) Handler added in v1.2.0

func (l *Websocket) Handler(w http.ResponseWriter, r *http.Request)

Handler upgrades and handles an incoming websocket connection.

func (*Websocket) ID

func (l *Websocket) ID() string

ID returns the id of the listener.

func (*Websocket) Init

func (l *Websocket) Init(log *slog.Logger) error

Init initializes the listener.

func (*Websocket) Protocol

func (l *Websocket) Protocol() string

Protocol returns the address of the listener.

func (*Websocket) Serve

func (l *Websocket) Serve(establish listeners.EstablishFn)

Serve starts waiting for new Websocket connections, and calls the connection establishment callback for any received.

type WebsocketListenerConfig added in v1.8.0

type WebsocketListenerConfig struct {
	ID   string `mapstructure:"id" default:"ws1"`
	Path string `mapstructure:"path" default:"/realtime"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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