asyncapi

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package "asyncapi" provides primitives to interact with the AsyncAPI specification.

Code generated by github.com/lerenn/asyncapi-codegen version v0.39.0 DO NOT EDIT.

Package "asyncapi" provides primitives to interact with the AsyncAPI specification.

Code generated by github.com/lerenn/asyncapi-codegen version v0.39.0 DO NOT EDIT.

Package "asyncapi" provides primitives to interact with the AsyncAPI specification.

Code generated by github.com/lerenn/asyncapi-codegen version v0.39.0 DO NOT EDIT.

Index

Constants

View Source
const (
	// ListeningChannelPath is the constant representing the 'ListeningChannel' channel path.
	ListeningChannelPath = "cryptellation.ticks.listening"
	// LiveChannelPath is the constant representing the 'LiveChannel' channel path.
	LiveChannelPath = "cryptellation.ticks.live.{exchange}.{pair}"
	// ServiceInfoRequestChannelPath is the constant representing the 'ServiceInfoRequestChannel' channel path.
	ServiceInfoRequestChannelPath = "cryptellation.ticks.info"
	// ServiceInfoResponseChannelPath is the constant representing the 'ServiceInfoResponseChannel' channel path.
	ServiceInfoResponseChannelPath = ""
)
View Source
const AsyncAPIVersion = "1.0.0"

AsyncAPIVersion is the version of the used AsyncAPI document

Variables

ChannelsPaths is an array of all channels paths

Functions

This section is empty.

Types

type AppController

type AppController struct {
	// contains filtered or unexported fields
}

AppController is the structure that provides sending capabilities to the developer and and connect the broker with the App

func NewAppController

func NewAppController(bc extensions.BrokerController, options ...ControllerOption) (*AppController, error)

NewAppController links the App to the broker

func (*AppController) Close

func (c *AppController) Close(ctx context.Context)

Close will clean up any existing resources on the controller

func (*AppController) ReplyToServiceInfoOperation

func (c *AppController) ReplyToServiceInfoOperation(ctx context.Context, recvMsg ServiceInfoRequestMessage, fn func(replyMsg *ServiceInfoResponseMessage)) error

ReplyToServiceInfoOperation is a helper function to reply to a ServiceInfoRequest message with a ServiceInfoResponse message on ServiceInfoResponse channel.

func (*AppController) SendAsReplyToServiceInfoOperation

func (c *AppController) SendAsReplyToServiceInfoOperation(
	ctx context.Context,
	chanAddr string,
	msg ServiceInfoResponseMessage,
) error

SendAsReplyToServiceInfoOperation will send a ServiceInfoResponse message on ServiceInfoResponse channel.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*AppController) SendAsSendNewTicksOperation added in v1.3.0

func (c *AppController) SendAsSendNewTicksOperation(
	ctx context.Context,
	params LiveChannelParameters,
	msg TickMessage,
) error

SendAsSendNewTicksOperation will send a Tick message on Live channel.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*AppController) SubscribeToAllChannels

func (c *AppController) SubscribeToAllChannels(ctx context.Context, as AppSubscriber) error

SubscribeToAllChannels will receive messages from channels where channel has no parameter on which the app is expecting messages. For channels with parameters, they should be subscribed independently.

func (*AppController) SubscribeToListeningOperation added in v1.3.0

func (c *AppController) SubscribeToListeningOperation(
	ctx context.Context,
	fn func(ctx context.Context, msg ListeningNotificationMessage) error,
) error

SubscribeToListeningOperation will receive ListeningNotification messages from Listening channel.

Callback function 'fn' will be called each time a new message is received.

NOTE: for now, this only support the first message from AsyncAPI list.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*AppController) SubscribeToServiceInfoOperation

func (c *AppController) SubscribeToServiceInfoOperation(
	ctx context.Context,
	fn func(ctx context.Context, msg ServiceInfoRequestMessage) error,
) error

Callback function 'fn' will be called each time a new message is received.

NOTE: for now, this only support the first message from AsyncAPI list.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*AppController) UnsubscribeFromAllChannels

func (c *AppController) UnsubscribeFromAllChannels(ctx context.Context)

UnsubscribeFromAllChannels will stop the subscription of all remaining subscribed channels

func (*AppController) UnsubscribeFromListeningOperation added in v1.3.0

func (c *AppController) UnsubscribeFromListeningOperation(
	ctx context.Context,
)

A timeout can be set in context to avoid blocking operation, if needed.

func (*AppController) UnsubscribeFromServiceInfoOperation

func (c *AppController) UnsubscribeFromServiceInfoOperation(
	ctx context.Context,
)

UnsubscribeFromServiceInfoOperation will stop the reception of ServiceInfoRequest messages from ServiceInfoRequest channel. A timeout can be set in context to avoid blocking operation, if needed.

type AppSubscriber

type AppSubscriber interface {
	// ListeningOperationReceived receive all ListeningNotification messages from Listening channel.
	ListeningOperationReceived(ctx context.Context, msg ListeningNotificationMessage) error

	// ServiceInfoOperationReceived receive all ServiceInfoRequest messages from ServiceInfoRequest channel.
	ServiceInfoOperationReceived(ctx context.Context, msg ServiceInfoRequestMessage) error
}

AppSubscriber contains all handlers that are listening messages for App

type ControllerOption

type ControllerOption func(controller *controller)

ControllerOption is the type of the options that can be passed when creating a new Controller

func WithErrorHandler

func WithErrorHandler(handler extensions.ErrorHandler) ControllerOption

WithErrorHandler attaches a errorhandler to handle errors from subscriber functions

func WithLogger

func WithLogger(logger extensions.Logger) ControllerOption

WithLogger attaches a logger to the controller

func WithMiddlewares

func WithMiddlewares(middlewares ...extensions.Middleware) ControllerOption

WithMiddlewares attaches middlewares that will be executed when sending or receiving messages

type DateSchema

type DateSchema time.Time

DateSchema is a schema from the AsyncAPI specification required in messages Description: Date-Time format according to RFC3339

func (DateSchema) MarshalJSON

func (t DateSchema) MarshalJSON() ([]byte, error)

MarshalJSON will override the marshal as this is not a normal 'time.Time' type

func (*DateSchema) UnmarshalJSON

func (t *DateSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON will override the unmarshal as this is not a normal 'time.Time' type

type Error

type Error struct {
	Channel string
	Err     error
}

func (*Error) Error

func (e *Error) Error() string

type ErrorSchema

type ErrorSchema struct {
	// Description: Code to identify the error type, based on HTTP errors
	Code int64 `json:"code"`

	// Description: Main error reason
	Message string `json:"message"`
}

ErrorSchema is a schema from the AsyncAPI specification required in messages Description: Response to a failed call

type ExchangeSchema

type ExchangeSchema string

ExchangeSchema is a schema from the AsyncAPI specification required in messages Description: Exchange name

type HeadersFromServiceInfoRequestMessage

type HeadersFromServiceInfoRequestMessage struct {
	// Description: Correlation ID set by client
	CorrelationId *string `json:"correlationId"`

	// Description: Channel used to respond to request
	ReplyTo string `json:"replyTo"`
}

HeadersFromServiceInfoRequestMessage is a schema from the AsyncAPI specification required in messages

type HeadersFromServiceInfoResponseMessage

type HeadersFromServiceInfoResponseMessage struct {
	// Description: Correlation ID set by client
	CorrelationId *string `json:"correlationId"`
}

HeadersFromServiceInfoResponseMessage is a schema from the AsyncAPI specification required in messages

type ListeningNotificationMessage added in v1.3.0

type ListeningNotificationMessage struct {
	// Payload will be inserted in the message payload
	Payload ListeningNotificationMessagePayload
}

ListeningNotificationMessage is the message expected for 'ListeningNotificationMessage' channel.

func NewListeningNotificationMessage added in v1.3.0

func NewListeningNotificationMessage() ListeningNotificationMessage

func (*ListeningNotificationMessage) FromModel added in v1.3.0

func (ListeningNotificationMessage) ToModel added in v1.3.0

type ListeningNotificationMessagePayload added in v1.3.0

type ListeningNotificationMessagePayload struct {
	// Description: Exchange name
	Exchange ExchangeSchema `json:"exchange"`

	// Description: Pair symbol
	Pair PairSchema `json:"pair"`
}

ListeningNotificationMessagePayload is a schema from the AsyncAPI specification required in messages

type LiveChannelParameters

type LiveChannelParameters struct {
	// Exchange is a channel parameter: Filter for ticks by exchange name
	Exchange string
	// Pair is a channel parameter: Filter for ticks by pair symbol
	Pair string
}

LiveChannelParameters represents LiveChannel channel parameters

type MessageWithCorrelationID

type MessageWithCorrelationID interface {
	CorrelationID() string
	SetCorrelationID(id string)
}

type PairSchema

type PairSchema string

PairSchema is a schema from the AsyncAPI specification required in messages Description: Pair symbol

type ServiceInfoRequestMessage

type ServiceInfoRequestMessage struct {
	// Headers will be used to fill the message headers
	Headers HeadersFromServiceInfoRequestMessage

	// Payload will be inserted in the message payload
	Payload ServiceInfoRequestMessagePayload
}

ServiceInfoRequestMessage is the message expected for 'ServiceInfoRequestMessage' channel.

func NewServiceInfoRequestMessage

func NewServiceInfoRequestMessage() ServiceInfoRequestMessage

func (ServiceInfoRequestMessage) CorrelationID

func (msg ServiceInfoRequestMessage) CorrelationID() string

CorrelationID will give the correlation ID of the message, based on AsyncAPI spec

func (*ServiceInfoRequestMessage) SetAsResponseFrom

func (msg *ServiceInfoRequestMessage) SetAsResponseFrom(req MessageWithCorrelationID)

SetAsResponseFrom will correlate the message with the one passed in parameter. It will assign the 'req' message correlation ID to the message correlation ID, both specified in AsyncAPI spec.

func (*ServiceInfoRequestMessage) SetCorrelationID

func (msg *ServiceInfoRequestMessage) SetCorrelationID(id string)

SetCorrelationID will set the correlation ID of the message, based on AsyncAPI spec

type ServiceInfoRequestMessagePayload

type ServiceInfoRequestMessagePayload struct{}

ServiceInfoRequestMessagePayload is a schema from the AsyncAPI specification required in messages

type ServiceInfoResponseMessage

type ServiceInfoResponseMessage struct {
	// Headers will be used to fill the message headers
	Headers HeadersFromServiceInfoResponseMessage

	// Payload will be inserted in the message payload
	Payload ServiceInfoResponseMessagePayload
}

ServiceInfoResponseMessage is the message expected for 'ServiceInfoResponseMessage' channel.

func NewServiceInfoResponseMessage

func NewServiceInfoResponseMessage() ServiceInfoResponseMessage

func (ServiceInfoResponseMessage) CorrelationID

func (msg ServiceInfoResponseMessage) CorrelationID() string

CorrelationID will give the correlation ID of the message, based on AsyncAPI spec

func (*ServiceInfoResponseMessage) SetAsResponseFrom

func (msg *ServiceInfoResponseMessage) SetAsResponseFrom(req MessageWithCorrelationID)

SetAsResponseFrom will correlate the message with the one passed in parameter. It will assign the 'req' message correlation ID to the message correlation ID, both specified in AsyncAPI spec.

func (*ServiceInfoResponseMessage) SetCorrelationID

func (msg *ServiceInfoResponseMessage) SetCorrelationID(id string)

SetCorrelationID will set the correlation ID of the message, based on AsyncAPI spec

func (ServiceInfoResponseMessage) ToModel

type ServiceInfoResponseMessagePayload

type ServiceInfoResponseMessagePayload struct {
	// Description: Version of the API
	ApiVersion string `json:"apiVersion"`

	// Description: Version of the binary
	BinVersion string `json:"binVersion"`
}

ServiceInfoResponseMessagePayload is a schema from the AsyncAPI specification required in messages

type TickMessage

type TickMessage struct {
	// Payload will be inserted in the message payload
	Payload TickSchema
}

TickMessage is the message expected for 'TickMessage' channel.

func NewTickMessage

func NewTickMessage() TickMessage

func (*TickMessage) FromModel added in v1.3.0

func (msg *TickMessage) FromModel(t tick.Tick)

func (TickMessage) ToModel

func (msg TickMessage) ToModel() tick.Tick

type TickSchema

type TickSchema struct {
	// Description: Exchange name
	Exchange ExchangeSchema `json:"exchange"`

	// Description: Pair symbol
	Pair PairSchema `json:"pair"`

	// Description: Tick price
	Price float64 `json:"price"`

	// Description: Date-Time format according to RFC3339
	Time DateSchema `json:"time"`
}

TickSchema is a schema from the AsyncAPI specification required in messages

type UserController

type UserController struct {
	// contains filtered or unexported fields
}

UserController is the structure that provides sending capabilities to the developer and and connect the broker with the User

func NewUserController

func NewUserController(bc extensions.BrokerController, options ...ControllerOption) (*UserController, error)

NewUserController links the User to the broker

func (*UserController) Close

func (c *UserController) Close(ctx context.Context)

Close will clean up any existing resources on the controller

func (*UserController) RequestToServiceInfoOperation

func (c *UserController) RequestToServiceInfoOperation(
	ctx context.Context,
	msg ServiceInfoRequestMessage,
) (ServiceInfoResponseMessage, error)

func (*UserController) SendToListeningOperation added in v1.3.0

func (c *UserController) SendToListeningOperation(
	ctx context.Context,
	msg ListeningNotificationMessage,
) error

SendToListeningOperation will send a ListeningNotification message on Listening channel.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*UserController) SendToServiceInfoOperation

func (c *UserController) SendToServiceInfoOperation(
	ctx context.Context,
	msg ServiceInfoRequestMessage,
) error

SendToServiceInfoOperation will send a ServiceInfoRequest message on ServiceInfoRequest channel.

NOTE: this won't wait for reply, use the normal version to get the reply or do the catching reply manually. NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*UserController) SubscribeToAllChannels

func (c *UserController) SubscribeToAllChannels(ctx context.Context, as UserSubscriber) error

SubscribeToAllChannels will receive messages from channels where channel has no parameter on which the app is expecting messages. For channels with parameters, they should be subscribed independently.

func (*UserController) SubscribeToSendNewTicksOperation added in v1.3.0

func (c *UserController) SubscribeToSendNewTicksOperation(
	ctx context.Context,
	params LiveChannelParameters,
	fn func(ctx context.Context, msg TickMessage) error,
) error

SubscribeToSendNewTicksOperation will receive Tick messages from Live channel.

Callback function 'fn' will be called each time a new message is received.

NOTE: for now, this only support the first message from AsyncAPI list.

NOTE: for now, this only support the first message from AsyncAPI list. If you need support for other messages, please raise an issue.

func (*UserController) UnsubscribeFromAllChannels

func (c *UserController) UnsubscribeFromAllChannels(ctx context.Context)

UnsubscribeFromAllChannels will stop the subscription of all remaining subscribed channels

func (*UserController) UnsubscribeFromSendNewTicksOperation added in v1.3.0

func (c *UserController) UnsubscribeFromSendNewTicksOperation(
	ctx context.Context,
	params LiveChannelParameters,
)

A timeout can be set in context to avoid blocking operation, if needed.

type UserSubscriber

type UserSubscriber interface {
	// SendNewTicksOperationReceived receive all Tick messages from Live channel.
	SendNewTicksOperationReceived(ctx context.Context, msg TickMessage) error
}

UserSubscriber contains all handlers that are listening messages for User

Jump to

Keyboard shortcuts

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