natsevents

package
v1.1.29 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventFillDefaults added in v0.1.16

func EventFillDefaults(e *event.Event)

EventFillDefaults fills the required field with default values if not already set

func NewEvent added in v1.1.19

func NewEvent(eventPrefix, eventType string, obj interface{}) *event.Event

NewEvent creates a cloud event given minimal parameters

func SNI added in v0.1.13

func SNI(serverName string) nats.Option

func WithTransport added in v0.1.11

func WithTransport(ctx context.Context, transport *NatsTransport) context.Context

WithTransport adds the transport as context value

Types

type CloudEventHandler

type CloudEventHandler func(topic string, event *cloudevents.Event, payload []byte, err error) (*cloudevents.Event, error)

CloudEventHandler : callback to handle CloudEvents must return as fast as possible. event can be nil, in this case the payload will be set if event is not nil (properly decoded) the payload is nil

type CloudEventReceiver

type CloudEventReceiver interface {
	RegisterHandler(eventHandler CloudEventHandler, topic string) error
	Respond(*event.Event, error)
}

CloudEventReceiver allows to receive cloud events

type CloudEventSender

type CloudEventSender interface {
	Flush(timeout time.Duration) error
	Send(ctx context.Context, event *event.Event, topic string) error
	Request(ctx context.Context, event *event.Event, topic string, timeout time.Duration) (*event.Event, error)
}

CloudEventSender Sends cloud events

type NatsTransport

type NatsTransport struct {
	CloudEventSender
	CloudEventReceiver
	// contains filtered or unexported fields
}

NatsTransport allows to send and receive CloudEvents on nats

func FromContext added in v0.1.11

func FromContext(ctx context.Context) *NatsTransport

FromContext returns the transport set with WithTransport or nil

func NewNatsTransport

func NewNatsTransport(server string) (*NatsTransport, error)

NewNatsTransport connects to nats and creates a NatsTransport

func (*NatsTransport) Close

func (t *NatsTransport) Close() error

Close closes the underlying nats connection

func (*NatsTransport) Connected

func (t *NatsTransport) Connected() bool

Connected returns true if nats is connected

func (*NatsTransport) Flush

func (t *NatsTransport) Flush(timeout time.Duration) error

Flush flushes nats pending writes

func (*NatsTransport) RegisterHandler

func (t *NatsTransport) RegisterHandler(eventHandler CloudEventHandler, topic string) error

func (*NatsTransport) Request

func (t *NatsTransport) Request(ctx context.Context, event *event.Event, topic string, timeout time.Duration) (*event.Event, error)

Request sends a request and waits the response for timeout

func (*NatsTransport) Send

func (t *NatsTransport) Send(ctx context.Context, event *event.Event, topic string) error

Send sends the json representation of the event on nats topic

type SNIDialer added in v0.1.13

type SNIDialer struct {
	ServerName string
}

func (*SNIDialer) Dial added in v0.1.13

func (d *SNIDialer) Dial(network, address string) (net.Conn, error)

type Transport

type Transport interface {
	CloudEventSender
	CloudEventReceiver
	io.Closer
}

type Transporter added in v0.1.11

type Transporter interface {
	Transport() Transport
	SetTransport(transport Transport)
}

Jump to

Keyboard shortcuts

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