Back to

Package transport

Latest Go to latest

The latest major version is .

Published: Feb 17, 2018 | License: MIT | Module:


Package transport is a generated protocol buffer package.

It is generated from these files:


It has these top-level messages:




var (
	DefaultRequestTimeout = 2 * time.Second

type Handler

type Handler func(msg *Message) (proto.Message, error)

Handler is the handler used by a subscriber. The return value may be nil if no output is yielded. If this is a request, the reply will be sent automatically with the reply value or an error if one occurred. If a reply is not expected and error occurs, it will be logged. The error can be inspected using status.FromError.

type Message

type Message struct {
	// ID is a globally unique message.
	Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
	// Timestamp is the timestamp in nanoseconds with the message was published.
	Timestamp uint64 `protobuf:"varint,2,opt,name=timestamp" json:"timestamp,omitempty"`
	// Payload is the actual payload being published that will be consumed.
	// This is expected to use protobuf encoding.
	Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"`
	// Deprecated. Use status instead.
	Error string `protobuf:"bytes,4,opt,name=error" json:"error,omitempty"`
	// Cause is the ID of a message that resulted in this message being published.
	Cause string `protobuf:"bytes,5,opt,name=cause" json:"cause,omitempty"`
	// Subject is the subject the message is published.
	Subject string `protobuf:"bytes,6,opt,name=subject" json:"subject,omitempty"`
	// Queue is the queue this message was received by.
	Queue string `protobuf:"bytes,7,opt,name=queue" json:"queue,omitempty"`
	// Reply is the inbox ID of the publisher of this message.
	Reply string `protobuf:"bytes,8,opt,name=reply" json:"reply,omitempty"`
	// Error that occurs in during transport or in the application.
	Status *google_rpc.Status `protobuf:"bytes,9,opt,name=status" json:"status,omitempty"`

Message is the envelope/wrapper for all messages.

func (*Message) Decode

func (m *Message) Decode(pb proto.Message) error

Decode decodes the message payload into a proto message.

func (*Message) Descriptor

func (*Message) Descriptor() ([]byte, []int)

func (*Message) GetCause

func (m *Message) GetCause() string

func (*Message) GetError

func (m *Message) GetError() string

func (*Message) GetId

func (m *Message) GetId() string

func (*Message) GetPayload

func (m *Message) GetPayload() []byte

func (*Message) GetQueue

func (m *Message) GetQueue() string

func (*Message) GetReply

func (m *Message) GetReply() string

func (*Message) GetStatus

func (m *Message) GetStatus() *google_rpc.Status

func (*Message) GetSubject

func (m *Message) GetSubject() string

func (*Message) GetTimestamp

func (m *Message) GetTimestamp() uint64

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) String

func (m *Message) String() string

type PublishOption

type PublishOption func(*PublishOptions)

func PublishCause

func PublishCause(s string) PublishOption

PublishCause sets the cause of the publication.

type PublishOptions

type PublishOptions struct {
	Cause string

PublishOptions are options for a publication.

type RequestOption

type RequestOption func(*RequestOptions)

func RequestCause

func RequestCause(s string) RequestOption

RequestCause sets the cause of the request.

func RequestTimeout

func RequestTimeout(t time.Duration) RequestOption

RequestTimeout sets a request timeout duration.

type RequestOptions

type RequestOptions struct {
	Cause   string
	Timeout time.Duration

RequestOptions are options for a publication.

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

func SubscribeQueue

func SubscribeQueue(q string) SubscribeOption

SubscribeQueue specifies the queue name of the subscriber.

type SubscribeOptions

type SubscribeOptions struct {
	Queue string

SubscribeOptions are options for a subscriber.

type Transport

type Transport interface {
	// Publish publishes a message asynchronously to the specified subject.
	// The wrapped message is returned or an error. The error would only be due to
	// a connection issue, but does not reflect any consumer error.
	Publish(sub string, msg proto.Message, opts ...PublishOption) (*Message, error)

	// Request publishes a message synchronously and waits for a response that
	// is decoded into the Protobuf message supplied. The wrapped message is
	// returned or an error. The error can inspected using status.FromError.
	Request(sub string, req proto.Message, rep proto.Message, opts ...RequestOption) (*Message, error)

	// Subscribe creates a subscription to a subject.
	Subscribe(sub string, hdl Handler, opts ...SubscribeOption) (*nats.Subscription, error)

	// Conn returns the underlying NATS connection.
	Conn() *nats.Conn

	// Close closes the transport connection and unsubscribes all subscribers.

	// Set the logger.

Transport describes the interface

func Connect

func Connect(opts *nats.Options) (Transport, error)

Connect is a convenience function establishing a connection with NATS and returning a transport.

func New

func New(conn *nats.Conn) Transport

New returns a transport using an existing NATS connection.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier