websocket

package module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

README

AWS WebSocket API Broker

The sub-module implements swarm broker for AWS WebSocket API. See the library documentation for details.

Note the broker implements only infrastructure required for making serverless applications using WebSocket APIs.

Use cli https://github.com/vi/websocat for testing purposes.

websocat wss://0000000000.execute-api.eu-west-1.amazonaws.com/ws/\?apikey=dGVzdDp0ZXN0\&scope=test
{"action":"User", "id":"xxx", "text":"some text"}

Documentation

Index

Constants

View Source
const (
	// Environment variable defines event category (the route function is bound with)
	EnvConfigEventCategory = "CONFIG_SWARM_WS_EVENT_CATEGORY"

	// Environment variable defines source WebSocket API Gateway
	EnvConfigSourceWebSocketUrl = "CONFIG_SWARM_SOURCE_WS_URL"

	// Environment variable defines target WebSocket API Gateway
	EnvConfigTargetWebSocketUrl = "CONFIG_SWARM_TARGET_WS_URL"
)
View Source
const Version = "broker/websocket/v0.24.0"

Variables

This section is empty.

Functions

func EmitEvent added in v0.24.0

func EmitEvent[E swarm.Event[M, T], M, T any](q *kernel.EmitterIO, codec ...kernel.Encoder[swarm.Event[M, T]]) (snd chan<- swarm.Event[M, T], dlq <-chan swarm.Event[M, T])

func Must added in v0.23.0

func Must[T any](v T, err error) T

func PrincipalOf added in v0.20.1

func PrincipalOf[T any](msg swarm.Msg[T]) (string, error)

Helper function to fetch principal identity from the context of websocket message

Types

type AuthorizerApiKeyProps

type AuthorizerApiKeyProps struct {
	Access string
	Secret string
	Scope  []string
}

type AuthorizerJwtProps

type AuthorizerJwtProps struct {
	Issuer   string
	Audience string
}

type AuthorizerUniversalProps

type AuthorizerUniversalProps struct {
	AuthorizerApiKey *AuthorizerApiKeyProps
	AuthorizerJwt    *AuthorizerJwtProps
}

type Broker

type Broker struct {
	constructs.Construct
	Gateway    awsapigatewayv2.WebSocketApi
	Authorizer awsapigatewayv2.IWebSocketRouteAuthorizer
	// contains filtered or unexported fields
}

func NewBroker

func NewBroker(scope constructs.Construct, id *string, props *BrokerProps) *Broker

func (*Broker) GrantRead added in v0.24.0

func (broker *Broker) GrantRead(f awslambda.Function)

Grant permission to read events from the EventBus.

func (*Broker) GrantWrite added in v0.24.0

func (broker *Broker) GrantWrite(f awslambda.Function)

Grant permission to write events to the WebSocket

func (*Broker) NewAuthorizerApiKey

func (broker *Broker) NewAuthorizerApiKey(props *AuthorizerApiKeyProps) awsapigatewayv2.IWebSocketRouteAuthorizer

func (*Broker) NewAuthorizerJwt

func (broker *Broker) NewAuthorizerJwt(props *AuthorizerJwtProps) awsapigatewayv2.IWebSocketRouteAuthorizer

func (*Broker) NewAuthorizerUniversal

func (broker *Broker) NewAuthorizerUniversal(props *AuthorizerUniversalProps) awsapigatewayv2.IWebSocketRouteAuthorizer

func (*Broker) NewGateway

func (broker *Broker) NewGateway(props *WebSocketApiProps) awsapigatewayv2.WebSocketApi

func (*Broker) NewSink

func (broker *Broker) NewSink(props *SinkProps) *Sink

type BrokerProps

type BrokerProps struct{}

type Client

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

func (*Client) Close added in v0.23.0

func (cli *Client) Close() error

func (*Client) Enq

func (cli *Client) Enq(ctx context.Context, bag swarm.Bag) error

Enq enqueues message to broker

type EmitterBuilder added in v0.23.0

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

func Emitter added in v0.23.0

func Emitter() *EmitterBuilder

func (*EmitterBuilder) Build added in v0.23.0

func (b *EmitterBuilder) Build(endpoint string) (*kernel.EmitterIO, error)

func (EmitterBuilder) WithKernel added in v0.23.0

func (b EmitterBuilder) WithKernel(opts ...opts.Option[swarm.Config]) T

WithKernel configures swarm kernel options for advanced usage.

func (EmitterBuilder) WithService added in v0.23.0

func (b EmitterBuilder) WithService(service Gateway) T

WithService configures AWS API Gateway Management API client instance

type EndpointBuilder added in v0.23.0

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

func Endpoint added in v0.23.0

func Endpoint() *EndpointBuilder

func (*EndpointBuilder) Build added in v0.23.0

func (b *EndpointBuilder) Build(endpoint string) (*kernel.Kernel, error)

func (EndpointBuilder) WithKernel added in v0.23.0

func (b EndpointBuilder) WithKernel(opts ...opts.Option[swarm.Config]) T

WithKernel configures swarm kernel options for advanced usage.

func (EndpointBuilder) WithService added in v0.23.0

func (b EndpointBuilder) WithService(service Gateway) T

WithService configures AWS API Gateway Management API client instance

type EventCodec added in v0.24.0

type EventCodec[E swarm.Event[M, T], M, T any] struct {
	encoding.Event[M, T]
	// contains filtered or unexported fields
}

func ForEvent added in v0.24.0

func ForEvent[E swarm.Event[M, T], M, T any](realm, agent string, category ...string) EventCodec[E, M, T]

func (EventCodec[E, M, T]) Encode added in v0.24.0

func (c EventCodec[E, M, T]) Encode(evt swarm.Event[M, T]) (swarm.Bag, error)

type Gateway

WebSocket declares the subset of interface from AWS SDK used by the lib.

type ListenerBuilder added in v0.23.0

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

func Listener added in v0.23.0

func Listener() *ListenerBuilder

func (*ListenerBuilder) Build added in v0.23.0

func (b *ListenerBuilder) Build() (*kernel.ListenerIO, error)

func (ListenerBuilder) WithKernel added in v0.23.0

func (b ListenerBuilder) WithKernel(opts ...opts.Option[swarm.Config]) T

WithKernel configures swarm kernel options for advanced usage.

func (ListenerBuilder) WithService added in v0.23.0

func (b ListenerBuilder) WithService(service Gateway) T

WithService configures AWS API Gateway Management API client instance

type Sink

type Sink struct {
	constructs.Construct
	Handler awslambda.Function
}

func NewSink

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink

type SinkProps

type SinkProps struct {
	Agent *string

	// Category of event to process. It is used to create a WebSocket route.
	Category string

	// Properties of Lambda function to handle the category
	Function scud.FunctionProps

	// WebSocket Api Gateway lambda is bound with
	Gateway awsapigatewayv2.WebSocketApi
}

type WebSocketApiProps

type WebSocketApiProps struct {
	*awsapigatewayv2.WebSocketApiProps
	Throttle *awsapigatewayv2.ThrottleSettings
	Host     *string
	TlsArn   *string
}

Directories

Path Synopsis
examples
dequeue/typed command
serverless command
lambda
auth command
connector command

Jump to

Keyboard shortcuts

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