Documentation ¶
Index ¶
- type CachingHandler
- func (c *CachingHandler) AllMetrics() []HostMetric
- func (c *CachingHandler) DeviceMetrics(descriptor EdgeNodeDescriptor, deviceID string) []HostMetric
- func (c *CachingHandler) EdgeNodeMetrics(descriptor EdgeNodeDescriptor) []HostMetric
- func (c *CachingHandler) GroupMetrics(groupID string) []HostMetric
- func (c *CachingHandler) HandleMetric(metric HostMetric)
- type EdgeNodeDescriptor
- type HostApplication
- func (h *HostApplication) Run(ctx context.Context) error
- func (h *HostApplication) SendDeviceCommand(descriptor EdgeNodeDescriptor, deviceID string, ...) error
- func (h *HostApplication) SendDeviceRebirthRequest(descriptor EdgeNodeDescriptor, deviceID string) error
- func (h *HostApplication) SendEdgeNodeCommand(descriptor EdgeNodeDescriptor, metrics []*protobuf.Payload_Metric) error
- func (h *HostApplication) SendEdgeNodeRebirthRequest(descriptor EdgeNodeDescriptor) error
- type HostMetric
- type MetricHandler
- type MetricQuality
- type MqttBrokerConfig
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachingHandler ¶ added in v0.2.0
type CachingHandler struct {
// contains filtered or unexported fields
}
CachingHandler is a MetricHandler that stores the latest known state of every metric in memory. It allows clients to get a snapshot view of all the current Edge Nodes and Devices on-demand. All operations in this handler are safe for concurrent use.
func NewCachingHandler ¶ added in v0.2.0
func NewCachingHandler() *CachingHandler
NewCachingHandler returns a new handler ready to be used.
func (*CachingHandler) AllMetrics ¶ added in v0.2.0
func (c *CachingHandler) AllMetrics() []HostMetric
AllMetrics returns all currently known metrics in the MQTT infrastructure.
func (*CachingHandler) DeviceMetrics ¶ added in v0.2.0
func (c *CachingHandler) DeviceMetrics(descriptor EdgeNodeDescriptor, deviceID string) []HostMetric
DeviceMetrics returns all known metrics for a specific Device.
func (*CachingHandler) EdgeNodeMetrics ¶ added in v0.2.0
func (c *CachingHandler) EdgeNodeMetrics(descriptor EdgeNodeDescriptor) []HostMetric
EdgeNodeMetrics returns all known metrics for a specific Edge Node. This includes the metrics for Devices associated with that Edge Node.
func (*CachingHandler) GroupMetrics ¶ added in v0.2.0
func (c *CachingHandler) GroupMetrics(groupID string) []HostMetric
GroupMetrics returns all known metrics for a specific Group. This includes all Edge Nodes and Devices in that group.
func (*CachingHandler) HandleMetric ¶ added in v0.2.0
func (c *CachingHandler) HandleMetric(metric HostMetric)
HandleMetric is a MetricHandler function that can be passed to WithMetricHandler when creating the HostApplication.
type EdgeNodeDescriptor ¶
EdgeNodeDescriptor is the combination of the Group ID and Edge Node ID. No two Edge Nodes within a Sparkplug environment can have the same Group ID and same Edge Node ID.
func (EdgeNodeDescriptor) String ¶
func (e EdgeNodeDescriptor) String() string
type HostApplication ¶
type HostApplication struct {
// contains filtered or unexported fields
}
func NewHostApplication ¶
func NewHostApplication(brokerConfigs []MqttBrokerConfig, hostID string, opts ...Option) (*HostApplication, error)
func (*HostApplication) Run ¶
func (h *HostApplication) Run(ctx context.Context) error
Run will connect to the mqtt broker and block until ctx is canceled.
func (*HostApplication) SendDeviceCommand ¶
func (h *HostApplication) SendDeviceCommand(descriptor EdgeNodeDescriptor, deviceID string, metrics []*protobuf.Payload_Metric) error
func (*HostApplication) SendDeviceRebirthRequest ¶
func (h *HostApplication) SendDeviceRebirthRequest(descriptor EdgeNodeDescriptor, deviceID string) error
func (*HostApplication) SendEdgeNodeCommand ¶
func (h *HostApplication) SendEdgeNodeCommand(descriptor EdgeNodeDescriptor, metrics []*protobuf.Payload_Metric) error
func (*HostApplication) SendEdgeNodeRebirthRequest ¶
func (h *HostApplication) SendEdgeNodeRebirthRequest(descriptor EdgeNodeDescriptor) error
type HostMetric ¶
type HostMetric struct { EdgeNodeDescriptor EdgeNodeDescriptor DeviceID string Metric *protobuf.Payload_Metric Quality MetricQuality }
HostMetric represents the view this Host Application has of a particular edge node or device metric.
type MetricHandler ¶
type MetricHandler func(HostMetric)
MetricHandler is a callback type which can be set to be executed upon the change of any of the known Edge Node or Device metrics. This includes when a metric is first received during BIRTH messages as well as updates through DATA or DEATH messages.
type MetricQuality ¶
type MetricQuality string
MetricQuality will be "STALE" when a given edge node or device looses connection to the MQTT broker. This represents that the data was accurate at a time, but now that the MQTT session has been lost can no longer be considered current or up to date.
const ( MetricQualityGood MetricQuality = "GOOD" MetricQualityStale MetricQuality = "STALE" )
type MqttBrokerConfig ¶
type MqttBrokerConfig struct { // URL of the broker. The format should be scheme://host:port // (e.g., tcp://localhost:1883). Required. BrokerURL string // Username if required by the broker. Optional. Username string // Password if required by the broker. Optional. Password string // SSL/TLS configuration to be used when connecting to an MQTT broker. // This can be used for brokers where the authentication needs to happen // via client certificates instead of username + password. Optional. TLSConfig *tls.Config }
MqttBrokerConfig contains the configuration parameters for each of the MQTT Brokers to be used.
type Option ¶
type Option func(*config)
Option allows clients to configure the Host Application.
func WithLogger ¶
WithLogger sets a `*slog.Logger` instance to use by the Host application. This allows clients to enable/disable DEBUG and INFO messages. The default logger sends everything to `io.Discard`.
func WithMetricHandler ¶
func WithMetricHandler(metricHandler MetricHandler) Option
WithMetricHandler sets a MetricHandler to be called when metrics are created or updated by this Host Application.
func WithReorderTimeout ¶
WithReorderTimeout sets a timeout on how long to wait before requesting a Rebirth when receiving messages out of order. Default: 5 seconds.