Documentation
¶
Index ¶
- Constants
- Variables
- func FormatMessage(pc domain.PubConfigInfo, msg *protomfx.Message) error
- func NormalizeSubtopic(topic string) (string, error)
- func PayloadHash(payload []byte) int32
- func SplitMessage(message protomfx.Message) ([]protomfx.Message, error)
- func ToJSONCommand(cmd protomfx.Command) mfjson.Command
- func ToJSONMessage(message protomfx.Message) mfjson.Message
- func ToSenMLMessage(message protomfx.Message) (senml.Message, error)
- type AlarmHandler
- type AlarmPublisher
- type AlarmSubscriber
- type Canceler
- type CommandHandler
- type CommandPublisher
- type CommandSubscriber
- type MessageDispatcher
- type MessageHandler
- type NotificationHandler
- type NotificationPublisher
- type NotificationSubscriber
- type PubSub
- type Publisher
- type Subscriber
- type WebhookHandler
- type WebhookPublisher
- type WebhookSubscriber
Constants ¶
const ( SenMLContentType = "application/senml+json" JSONContentType = "application/json" )
Variables ¶
var ( // ErrPublishMessage indicates that message publishing failed. ErrPublishMessage = errors.New("failed to publish message") // ErrPublishCommand indicates that command publishing failed. ErrPublishCommand = errors.New("failed to publish command") // ErrPublishAlarm indicates that alarm publishing failed. ErrPublishAlarm = errors.New("failed to publish alarm") // ErrPublishNotification indicates that notification publishing failed. ErrPublishNotification = errors.New("failed to publish notification") // ErrPublishWebhook indicates that webhook publishing failed. ErrPublishWebhook = errors.New("failed to publish webhook") // ErrMalformedSubtopic indicates that the subtopic is malformed. ErrMalformedSubtopic = errors.New("malformed subtopic") )
var ( // ErrFailedSubscribe indicates that subscribing to a topic failed. ErrFailedSubscribe = errors.New("failed to subscribe") // ErrFailedUnsubscribe indicates that unsubscribing from a topic failed. ErrFailedUnsubscribe = errors.New("failed to unsubscribe") // ErrSubscribeTimeout indicates that the subscription failed due to timeout. ErrSubscribeTimeout = errors.New("failed to subscribe due to timeout reached") // ErrUnsubscribeTimeout indicates that unsubscribe failed due to timeout. ErrUnsubscribeTimeout = errors.New("failed to unsubscribe due to timeout reached") // ErrUnsubscribeDeleteTopic indicates that unsubscribe failed because the topic was deleted. ErrUnsubscribeDeleteTopic = errors.New("failed to unsubscribe due to deletion of topic") // ErrNotSubscribed indicates that the topic is not subscribed to. ErrNotSubscribed = errors.New("not subscribed") // ErrEmptyTopic indicates the absence of topic. ErrEmptyTopic = errors.New("empty topic") // ErrEmptyID indicates the absence of ID. ErrEmptyID = errors.New("empty ID") )
var ErrInvalidContentType = errors.New("invalid content type")
ErrInvalidContentType indicates an invalid Content-Type
Functions ¶
func FormatMessage ¶ added in v0.26.0
func FormatMessage(pc domain.PubConfigInfo, msg *protomfx.Message) error
func NormalizeSubtopic ¶ added in v0.35.0
NormalizeSubtopic decodes a client-supplied subtopic and converts it into the dot-separated form used in subjects, rejecting any element containing a NATS wildcard token (* or >) so a subtopic can't smuggle one in.
func PayloadHash ¶ added in v0.42.0
func SplitMessage ¶ added in v0.28.0
Types ¶
type AlarmHandler ¶ added in v0.40.0
AlarmHandler handles a received protomfx.Alarm for AlarmSubscriber.
type AlarmPublisher ¶ added in v0.40.0
type AlarmPublisher interface {
// PublishAlarm publishes an alarm to the message broker.
PublishAlarm(subject string, alarm protomfx.Alarm) error
}
AlarmPublisher specifies the alarm publishing API.
type AlarmSubscriber ¶ added in v0.40.0
type AlarmSubscriber interface {
// SubscribeAlarms subscribes to the alarm stream.
SubscribeAlarms(id string, handler AlarmHandler) error
}
AlarmSubscriber specifies the alarm subscription API.
type Canceler ¶ added in v0.43.0
type Canceler interface {
Cancel() error
}
Canceler is an optional capability a MessageHandler may implement for cleanup when its subscription ends. Subscriber implementations detect it via a type assertion.
type CommandHandler ¶ added in v0.41.0
CommandHandler handles a received protomfx.Command for CommandSubscriber.
type CommandPublisher ¶ added in v0.41.0
type CommandPublisher interface {
// PublishCommand publishes a command to the message broker.
PublishCommand(subject string, cmd protomfx.Command) error
}
CommandPublisher specifies the command publishing API.
type CommandSubscriber ¶ added in v0.41.0
type CommandSubscriber interface {
// SubscribeCommands subscribes to the command stream for the given topic.
SubscribeCommands(id, topic string, handler CommandHandler) error
}
CommandSubscriber specifies the command subscription API.
type MessageDispatcher ¶ added in v0.42.0
type MessageDispatcher interface {
// Dispatch publishes msg to every subject enabled by the dispatcher flags in pc.
Dispatch(msg protomfx.Message, pc *domain.ProfileConfig) error
}
MessageDispatcher routes a message to every subject enabled by a profile's dispatcher flags.
type MessageHandler ¶
type MessageHandler interface {
// Handle handles messages passed by underlying implementation.
Handle(subject string, msg protomfx.Message) error
}
MessageHandler represents protomfx.Message handler for Subscriber.
type NotificationHandler ¶ added in v0.42.0
type NotificationHandler func(subject string, notification protomfx.Notification) error
NotificationHandler handles a received protomfx.Notification for NotificationSubscriber.
type NotificationPublisher ¶ added in v0.42.0
type NotificationPublisher interface {
// PublishNotification publishes a notification to the message broker.
PublishNotification(subject string, notification protomfx.Notification) error
}
NotificationPublisher specifies the notification publishing API.
type NotificationSubscriber ¶ added in v0.42.0
type NotificationSubscriber interface {
// SubscribeNotifications subscribes to the notification stream for the given topic.
SubscribeNotifications(id, topic string, handler NotificationHandler) error
}
NotificationSubscriber specifies the notification subscription API.
type PubSub ¶
type PubSub interface {
Publisher
Subscriber
}
PubSub represents aggregation interface for publisher and subscriber.
type Publisher ¶
type Publisher interface {
// Publish publishes message to the message broker.
Publish(subject string, msg protomfx.Message) error
// Close gracefully closes message publisher's connection.
Close() error
}
Publisher specifies message publishing API.
type Subscriber ¶
type Subscriber interface {
// Subscribe subscribes to the message stream and consumes messages.
Subscribe(id, topic string, handler MessageHandler) error
// Unsubscribe unsubscribes from the message stream and
// stops consuming messages.
Unsubscribe(id, topic string) error
// Close gracefully closes message subscriber's connection.
Close() error
}
Subscriber specifies message subscription API.
type WebhookHandler ¶ added in v0.42.0
WebhookHandler handles a received protomfx.Webhook for WebhookSubscriber.
type WebhookPublisher ¶ added in v0.42.0
type WebhookPublisher interface {
// PublishWebhook publishes a webhook message to the message broker.
PublishWebhook(subject string, webhook protomfx.Webhook) error
}
WebhookPublisher specifies the webhook publishing API.
type WebhookSubscriber ¶ added in v0.42.0
type WebhookSubscriber interface {
// SubscribeWebhooks subscribes to the webhook stream.
SubscribeWebhooks(id string, handler WebhookHandler) error
}
WebhookSubscriber specifies the webhook subscription API.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mqtt hold the implementation of the Publisher and PubSub interfaces for the MQTT messaging system, the internal messaging broker of the Mainflux IoT platform.
|
Package mqtt hold the implementation of the Publisher and PubSub interfaces for the MQTT messaging system, the internal messaging broker of the Mainflux IoT platform. |
|
Package nats implements messaging.Publisher and messaging.Subscriber (plus the typed Alarm/Command/Notification/Webhook streams) for NATS JetStream, the internal message broker of the Mainflux IoT platform.
|
Package nats implements messaging.Publisher and messaging.Subscriber (plus the typed Alarm/Command/Notification/Webhook streams) for NATS JetStream, the internal message broker of the Mainflux IoT platform. |