Documentation ¶
Overview ¶
Package ws provides domain concept definitions required to support Magistrala WebSocket adapter service functionality.
This package defines the core domain concepts and types necessary to handle WebSocket connections and messages in the context of a Magistrala WebSocket adapter service. It abstracts the underlying complexities of WebSocket communication and provides a structured approach to working with WebSocket clients and servers.
For more details about Magistrala messaging and WebSocket adapter service, please refer to the documentation at https://docs.magistrala.abstractmachines.fr/messaging/#websocket.
Index ¶
Constants ¶
const ( LogInfoSubscribed = "subscribed with client_id %s to topics %s" LogInfoUnsubscribed = "unsubscribed client_id %s from topics %s" LogInfoConnected = "connected with client_id %s" LogInfoDisconnected = "disconnected client_id %s and username %s" LogInfoPublished = "published with client_id %s to the topic %s" )
Log message formats.
Variables ¶
var ( // ErrFailedMessagePublish indicates that message publishing failed. ErrFailedMessagePublish = errors.New("failed to publish message") // ErrFailedSubscription indicates that client couldn't subscribe to specified channel. ErrFailedSubscription = errors.New("failed to subscribe to a channel") // ErrFailedUnsubscribe indicates that client couldn't unsubscribe from specified channel. ErrFailedUnsubscribe = errors.New("failed to unsubscribe from a channel") // ErrFailedConnection indicates that service couldn't connect to message broker. ErrFailedConnection = errors.New("failed to connect to message broker") // ErrInvalidConnection indicates that client couldn't subscribe to message broker. ErrInvalidConnection = errors.New("nats: invalid connection") ErrUnauthorizedAccess = errors.New("missing or invalid credentials provided") // ErrEmptyTopic indicate absence of thingKey in the request. ErrEmptyTopic = errors.New("empty topic") // ErrEmptyID indicate absence of channelID in the request. ErrEmptyID = errors.New("empty id") )
var ( ErrMalformedSubtopic = errors.New("malformed subtopic") ErrClientNotInitialized = errors.New("client is not initialized") ErrMalformedTopic = errors.New("malformed topic") ErrMissingClientID = errors.New("client_id not found") ErrMissingTopicPub = errors.New("failed to publish due to missing topic") ErrMissingTopicSub = errors.New("failed to subscribe due to missing topic") ErrFailedConnect = errors.New("failed to connect") ErrFailedSubscribe = errors.New("failed to subscribe") ErrFailedPublish = errors.New("failed to publish") ErrFailedDisconnect = errors.New("failed to disconnect") ErrFailedPublishDisconnectEvent = errors.New("failed to publish disconnect event") ErrFailedParseSubtopic = errors.New("failed to parse subtopic") ErrFailedPublishConnectEvent = errors.New("failed to publish connect event") ErrFailedPublishToMsgBroker = errors.New("failed to publish to magistrala message broker") )
Error wrappers for MQTT errors.
Functions ¶
func NewHandler ¶
func NewHandler(pubsub messaging.PubSub, logger *slog.Logger, authClient magistrala.AuthzServiceClient) session.Handler
NewHandler creates new Handler entity.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles messaging and websocket connection.
type Service ¶
type Service interface { // Subscribe subscribes message from the broker using the thingKey for authorization, // and the channelID for subscription. Subtopic is optional. // If the subscription is successful, nil is returned otherwise error is returned. Subscribe(ctx context.Context, thingKey, chanID, subtopic string, client *Client) error }
Service specifies web socket service API.
func New ¶
func New(authClient magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service
New instantiates the WS adapter implementation.
Directories ¶
Path | Synopsis |
---|---|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
Package tracing provides tracing instrumentation for Magistrala WebSocket adapter service.
|
Package tracing provides tracing instrumentation for Magistrala WebSocket adapter service. |