nats

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Overview

Package nats implements the CloudEvent transport implementation using NATS.

Index

Constants

View Source
const (
	// TransportName is the name of this transport.
	TransportName = "NATS"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	Encoding Encoding
	// contains filtered or unexported fields
}

func (*Codec) Decode

func (c *Codec) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error)

func (*Codec) Encode

type CodecStructured

type CodecStructured struct {
	Encoding Encoding
}

CodecStructured represents an structured http transport codec for all versions. Intended to be used as a base class.

type CodecV02

type CodecV02 struct {
	CodecStructured

	Encoding Encoding
}

func (CodecV02) Decode

func (CodecV02) Encode

type CodecV03

type CodecV03 struct {
	CodecStructured

	Encoding Encoding
}

func (CodecV03) Decode

func (CodecV03) Encode

type CodecV1 added in v0.10.0

type CodecV1 struct {
	CodecStructured

	Encoding Encoding
}

func (CodecV1) Decode added in v0.10.0

func (v CodecV1) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error)

func (CodecV1) Encode added in v0.10.0

type Encoding

type Encoding int32

Encoding to use for NATS transport.

const (
	// Default allows NATS transport implementation to pick.
	Default Encoding = iota
	// StructuredV02 is Structured CloudEvents spec v0.2.
	StructuredV02
	// StructuredV03 is Structured CloudEvents spec v0.3.
	StructuredV03
	// StructuredV1 is Structured CloudEvents spec v1.0.
	StructuredV1
	// Unknown is unknown.
	Unknown
)

func (Encoding) String

func (e Encoding) String() string

String pretty-prints the encoding as a string.

func (Encoding) Version

func (e Encoding) Version() string

Version pretty-prints the encoding version as a string.

type Message

type Message struct {
	Body []byte
}

func (Message) CloudEventsVersion

func (m Message) CloudEventsVersion() string

type Option

type Option func(*Transport) error

Option is the function signature required to be considered an nats.Option.

func WithConnOptions added in v0.10.2

func WithConnOptions(opts ...nats.Option) Option

WithConnOptions supplies NATS connection options that will be used when setting up the internal NATS connection

func WithEncoding

func WithEncoding(encoding Encoding) Option

WithEncoding sets the encoding for NATS transport.

type Transport

type Transport struct {
	Encoding    Encoding
	Conn        *nats.Conn
	ConnOptions []nats.Option
	NatsURL     string
	Subject     string

	Receiver transport.Receiver
	// Converter is invoked if the incoming transport receives an undecodable
	// message.
	Converter transport.Converter
	// contains filtered or unexported fields
}

Transport acts as both a NATS client and a NATS handler.

func New

func New(natsURL, subject string, opts ...Option) (*Transport, error)

New creates a new NATS transport.

func (*Transport) HasConverter

func (t *Transport) HasConverter() bool

HasConverter implements Transport.HasConverter

func (*Transport) HasTracePropagation added in v1.1.0

func (t *Transport) HasTracePropagation() bool

HasTracePropagation implements Transport.HasTracePropagation

func (*Transport) Send

Send implements Transport.Send

func (*Transport) SetConverter

func (t *Transport) SetConverter(c transport.Converter)

SetConverter implements Transport.SetConverter

func (*Transport) SetReceiver

func (t *Transport) SetReceiver(r transport.Receiver)

SetReceiver implements Transport.SetReceiver

func (*Transport) StartReceiver

func (t *Transport) StartReceiver(ctx context.Context) (err error)

StartReceiver implements Transport.StartReceiver NOTE: This is a blocking call.

Jump to

Keyboard shortcuts

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