application_headers

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package application_headers is generated from the official AsyncAPI example application-headers-asyncapi.yml.

Index

Constants

View Source
const LightingMeasuredAddressTemplate = "smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured"

LightingMeasuredAddressTemplate is the address of the LightingMeasured channel with its parameters unfilled.

View Source
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.

View Source
const MessageLightMeasuredCorrelationIDLocation = "$message.header#/MQMD/CorrelId"

MessageLightMeasuredCorrelationIDLocation is where a lightMeasured message carries its correlation ID, as an AsyncAPI runtime expression.

View Source
const (
	// Test broker
	ServerProductionURL = "mqtt://test.mosquitto.org:1883"
)

Server URLs, with any server variables at their defaults.

View Source
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

func LightingMeasuredAddress(streetlightID string) string

LightingMeasuredAddress returns the address of the LightingMeasured channel with its parameters filled in.

func ServerProductionURLWith

func ServerProductionURLWith(port string) string

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.

func (*Client) Close

func (c *Client) Close() error

Close closes the transport.

func (*Client) Run

func (c *Client) Run(ctx context.Context, handler Handler) error

Run reads messages until ctx ends or the transport fails and passes each one to handler. Messages that match nothing go to HandleUnknownMessage. Run stops at the first error a handler returns.

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

type ReceivedMessage struct {
	Name    string
	Payload any
}

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 SentAt

type SentAt = time.Time

type UnimplementedHandler

type UnimplementedHandler struct{}

UnimplementedHandler ignores every message. Its HandleUnknownMessage logs a warning and keeps the receive loop running.

func (UnimplementedHandler) HandleLightMeasured

HandleLightMeasured ignores the message.

func (UnimplementedHandler) HandleUnknownMessage

func (UnimplementedHandler) HandleUnknownMessage(ctx context.Context, data []byte, err error) error

HandleUnknownMessage logs the message size and the reason, then continues.

Jump to

Keyboard shortcuts

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