websocket

package module
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2025 License: Apache-2.0 Imports: 24 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 EnvConfigEventType = "CONFIG_SWARM_WS_EVENT_TYPE"

Environment variable to config event source

View Source
const EnvConfigSourceWebSocket = "CONFIG_SWARM_WS_URL"
View Source
const Version = "broker/websocket/v0.21.0"

Variables

View Source
var (
	// Passes AWS SQS client instance to broker
	WithService = opts.ForType[Client, Gateway]()
)

Functions

func New

func New(endpoint string, opts ...Option) (*kernel.Kernel, error)

Create enqueue & dequeue routines to WebSocket (AWS API Gateway)

func NewDequeuer added in v0.20.0

func NewDequeuer(opt ...Option) (*kernel.Dequeuer, error)

Creates dequeue routine from WebSocket (AWS API Gateway)

func NewEnqueuer added in v0.20.0

func NewEnqueuer(endpoint string, opts ...Option) (*kernel.Enqueuer, error)

Create enqueue routine to WebSocket (AWS API Gateway)

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) 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 {
	System string
}

type Client

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

func (*Client) Enq

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

Enq enqueues message to broker

type Gateway

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

type Option added in v0.20.0

type Option = opts.Option[Client]

func WithConfig added in v0.20.0

func WithConfig(opt ...opts.Option[swarm.Config]) Option

Global "kernel" configuration.

type Sink

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

func NewSink

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

type SinkProps

type SinkProps struct {
	Route    string
	Function scud.FunctionProps
	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