Documentation
¶
Overview ¶
Package application_headers is generated from the official AsyncAPI example application-headers-asyncapi.yml.
Index ¶
- Constants
- func Dispatch(ctx context.Context, handler Handler, message ReceivedMessage) error
- func LightingMeasuredAddress(streetlightID string) string
- func ServerProductionURLWith(port string) string
- type ApplicationInstanceID
- type Client
- type Handler
- type LightMeasuredHeaders
- type LightMeasuredHeadersMqmd
- type LightMeasuredPayload
- type ReceivedMessage
- type SentAt
- type UnimplementedHandler
Constants ¶
const LightingMeasuredAddressTemplate = "smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured"
LightingMeasuredAddressTemplate is the address of the LightingMeasured channel with its parameters unfilled.
const ( // Inform about environmental lighting conditions of a particular streetlight. // Payload: LightMeasuredPayload. // Application headers: LightMeasuredHeaders. // Content type: application/json. MessageLightMeasured = "lightMeasured" )
Message names, as the spec gives them.
const MessageLightMeasuredCorrelationIDLocation = "$message.header#/MQMD/CorrelId"
MessageLightMeasuredCorrelationIDLocation is where a lightMeasured message carries its correlation ID, as an AsyncAPI runtime expression.
const (
// Test broker
ServerProductionURL = "mqtt://test.mosquitto.org:1883"
)
Server URLs, with any server variables at their defaults.
const ServerProductionURLTemplate = "mqtt://test.mosquitto.org:{port}"
ServerProductionURLTemplate is the ServerProduction URL with its variables unfilled.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch(ctx context.Context, handler Handler, message ReceivedMessage) error
Dispatch passes message to the handler method for its name.
func LightingMeasuredAddress ¶
LightingMeasuredAddress returns the address of the LightingMeasured channel with its parameters filled in.
func ServerProductionURLWith ¶
ServerProductionURLWith returns the ServerProduction URL with its variables filled in.
Types ¶
type ApplicationInstanceID ¶
type ApplicationInstanceID = string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends and receives this API's messages over a transport.
func NewClient ¶
func NewClient(transport asyncapirt.Transport) *Client
NewClient returns a client that uses transport.
type Handler ¶
type Handler interface {
// Inform about environmental lighting conditions of a particular streetlight.
// Payload: LightMeasuredPayload.
// Application headers: LightMeasuredHeaders.
// Content type: application/json.
HandleLightMeasured(ctx context.Context, payload LightMeasuredPayload) error
// HandleUnknownMessage gets every message that matched nothing, with the
// reason. Returning an error stops Client.Run.
HandleUnknownMessage(ctx context.Context, data []byte, err error) error
}
Handler receives incoming messages. Embed UnimplementedHandler to implement only the methods you need.
type LightMeasuredHeaders ¶
type LightMeasuredHeaders struct {
Mqmd *LightMeasuredHeadersMqmd `json:"MQMD,omitempty"`
// Unique identifier for a given instance of the publishing application
ApplicationInstanceID *ApplicationInstanceID `json:"applicationInstanceId,omitempty"`
}
func (*LightMeasuredHeaders) UnmarshalJSON ¶
func (v *LightMeasuredHeaders) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes LightMeasuredHeaders strictly. Required properties must be present and the decoded value must pass Validate.
func (LightMeasuredHeaders) Validate ¶
func (v LightMeasuredHeaders) Validate() error
Validate checks the constraints the schema declares for LightMeasuredHeaders.
type LightMeasuredHeadersMqmd ¶
type LightMeasuredHeadersMqmd struct {
// Not enforced by the generated code: format binary.
CorrelID *string `json:"CorrelId,omitempty"`
}
func (*LightMeasuredHeadersMqmd) UnmarshalJSON ¶
func (v *LightMeasuredHeadersMqmd) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes LightMeasuredHeadersMqmd strictly. Required properties must be present and the decoded value must pass Validate.
func (LightMeasuredHeadersMqmd) Validate ¶
func (v LightMeasuredHeadersMqmd) Validate() error
Validate checks the constraints the schema declares for LightMeasuredHeadersMqmd.
type LightMeasuredPayload ¶
type LightMeasuredPayload struct {
// Light intensity measured in lumens.
Lumens *int64 `json:"lumens,omitempty"`
// Date and time when the message was sent.
SentAt *SentAt `json:"sentAt,omitempty"`
}
func (*LightMeasuredPayload) UnmarshalJSON ¶
func (v *LightMeasuredPayload) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes LightMeasuredPayload strictly. Required properties must be present and the decoded value must pass Validate.
func (LightMeasuredPayload) Validate ¶
func (v LightMeasuredPayload) Validate() error
Validate checks the constraints the schema declares for LightMeasuredPayload.
type ReceivedMessage ¶
ReceivedMessage is a decoded incoming message. Payload holds the payload type of the message Name names.
func DecodeReceivedMessage ¶
func DecodeReceivedMessage(data []byte) (ReceivedMessage, error)
DecodeReceivedMessage works out which incoming message data is and decodes it. It fails with asyncapirt.ErrUnknownMessage when nothing matches and asyncapirt.ErrAmbiguousMessage when several messages match.
type UnimplementedHandler ¶
type UnimplementedHandler struct{}
UnimplementedHandler ignores every message. Its HandleUnknownMessage logs a warning and keeps the receive loop running.
func (UnimplementedHandler) HandleLightMeasured ¶
func (UnimplementedHandler) HandleLightMeasured(context.Context, LightMeasuredPayload) error
HandleLightMeasured ignores the message.
func (UnimplementedHandler) HandleUnknownMessage ¶
HandleUnknownMessage logs the message size and the reason, then continues.