natsproxy

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func DefaultSubjectForAgentFunc

func DefaultSubjectForAgentFunc(agentID string) string

DefaultSubjectForAgentFunc returns the default NATS subject for a given agent

func NewResponseWriter

func NewResponseWriter(transport responseSender) http.ResponseWriter

NewResponseWriter returns an instance of ResponseWriter

func SerializeMap

func SerializeMap(m map[string][]string) map[string]*Values

SerializeMap converts golang map to protobuf map.

func SetupConnOptions

func SetupConnOptions(opts []nats.Option) []nats.Option

SetupConnOptions sets up defaults for nats connection

func UnserializeMap

func UnserializeMap(m map[string]*Values) map[string][]string

UnserializeMap converts protobuf map to golang map

Types

type Agent

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

Agent listens for incoming proxy requests for a given agent.

func NewAgent

func NewAgent(nc *nats.Conn, id uuid.UUID, handler http.Handler, subject string, keepAliveInterval time.Duration) *Agent

NewAgent will connect to nats in main cluster and proxy connections locally to an http.Handler. TODO: add reasonable defaults for keepAliveInterval

func (*Agent) Drain

func (a *Agent) Drain() error

Drain de-registers interest in all subscriptions and drains connections to gracefully shut down.

func (*Agent) IsDraining

func (a *Agent) IsDraining() bool

IsDraining verifies the state of Drain on the nats connection

func (*Agent) Listen

func (a *Agent) Listen() error

Listen initiates nats queue subscription for the agent.

type AgentResponseBroker

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

AgentResponseBroker that brokers the nats messages stream generated by AgentResponseWriter back into an http response, use NewAgentResponseBroker to initialize.

func NewAgentResponseBroker

func NewAgentResponseBroker(w http.ResponseWriter) *AgentResponseBroker

NewAgentResponseBroker returns an initialized AgentResponseBroker that brokers the nats messages stream generated by AgentResponseWriter back into an http response.

type HTTPProxy

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

HTTPProxy proxies http requests through nats to a remote agent

func NewHTTPProxy

func NewHTTPProxy(nc *nats.Conn, readTimeout time.Duration) *HTTPProxy

NewHTTPProxy returns an instance that proxies http requests through nats to a remote agent

func (*HTTPProxy) ServeHTTP

func (p *HTTPProxy) ServeHTTP(w http.ResponseWriter, req *http.Request, subject string)

ServeHTTP Serve HTTP request over nats

type RandomSuffix

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

RandomSuffix will generate a random suffix for use in Nats Msg.reply field.

func (*RandomSuffix) Get

func (r *RandomSuffix) Get() string

Get a random suffix from generator

type RandomSuffixGetter

type RandomSuffixGetter interface {
	Get() string
}

RandomSuffixGetter defines interface get a random suffix for a nats message.

type Request

type Request struct {
	TransportInfo *TransportInfo     `protobuf:"bytes,1,opt,name=transportInfo,proto3" json:"transportInfo,omitempty"`
	URL           string             `protobuf:"bytes,2,opt,name=URL,proto3" json:"URL,omitempty"`
	Method        string             `protobuf:"bytes,3,opt,name=Method,proto3" json:"Method,omitempty"`
	RemoteAddr    string             `protobuf:"bytes,4,opt,name=RemoteAddr,proto3" json:"RemoteAddr,omitempty"`
	Body          []byte             `protobuf:"bytes,5,opt,name=Body,proto3" json:"Body,omitempty"`
	Form          map[string]*Values `` /* 149-byte string literal not displayed */
	Header        map[string]*Values `` /* 153-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

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

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetBody

func (x *Request) GetBody() []byte

func (*Request) GetForm

func (x *Request) GetForm() map[string]*Values

func (*Request) GetHeader

func (x *Request) GetHeader() map[string]*Values

func (*Request) GetMethod

func (x *Request) GetMethod() string

func (*Request) GetRemoteAddr

func (x *Request) GetRemoteAddr() string

func (*Request) GetTransportInfo

func (x *Request) GetTransportInfo() *TransportInfo

func (*Request) GetURL

func (x *Request) GetURL() string

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	TransportInfo *TransportInfo     `protobuf:"bytes,1,opt,name=transportInfo,proto3" json:"transportInfo,omitempty"`
	StatusCode    int32              `protobuf:"varint,2,opt,name=StatusCode,proto3" json:"StatusCode,omitempty"`
	Header        map[string]*Values `` /* 153-byte string literal not displayed */
	Body          []byte             `protobuf:"bytes,4,opt,name=Body,proto3" json:"Body,omitempty"`
	DoUpgrade     bool               `protobuf:"varint,5,opt,name=DoUpgrade,proto3" json:"DoUpgrade,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

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

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetBody

func (x *Response) GetBody() []byte

func (*Response) GetDoUpgrade

func (x *Response) GetDoUpgrade() bool

func (*Response) GetHeader

func (x *Response) GetHeader() map[string]*Values

func (*Response) GetStatusCode

func (x *Response) GetStatusCode() int32

func (*Response) GetTransportInfo

func (x *Response) GetTransportInfo() *TransportInfo

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type ResponseWriter

type ResponseWriter struct {
	Committed bool
	Status    int
	// contains filtered or unexported fields
}

ResponseWriter serializes and writes http responses over nats as part of Agent.

func (*ResponseWriter) Flush

func (rw *ResponseWriter) Flush()

Flush does nothing, but conforms to flusher interface to maintain interoperable behavior with the previous proxy that is still in use.

func (*ResponseWriter) Header

func (rw *ResponseWriter) Header() http.Header

Header returns the header map of the Response

func (*ResponseWriter) Write

func (rw *ResponseWriter) Write(p []byte) (n int, err error)

Write will write bytes to body of the response. If headers have not been written this will write headers.

func (*ResponseWriter) WriteHeader

func (rw *ResponseWriter) WriteHeader(code int)

WriteHeader writes the http code and headers to output.

type SubjectForAgentFunc

type SubjectForAgentFunc func(agentID string) string

SubjectForAgentFunc is function to obtains NATS subject for a given agent ID

type TransportInfo

type TransportInfo struct {
	Sequence  int32 `protobuf:"varint,1,opt,name=Sequence,proto3" json:"Sequence,omitempty"`
	KeepAlive bool  `protobuf:"varint,2,opt,name=KeepAlive,proto3" json:"KeepAlive,omitempty"`
	Closing   bool  `protobuf:"varint,3,opt,name=Closing,proto3" json:"Closing,omitempty"`
	// contains filtered or unexported fields
}

func (*TransportInfo) Descriptor deprecated

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

Deprecated: Use TransportInfo.ProtoReflect.Descriptor instead.

func (*TransportInfo) GetClosing

func (x *TransportInfo) GetClosing() bool

func (*TransportInfo) GetKeepAlive

func (x *TransportInfo) GetKeepAlive() bool

func (*TransportInfo) GetSequence

func (x *TransportInfo) GetSequence() int32

func (*TransportInfo) ProtoMessage

func (*TransportInfo) ProtoMessage()

func (*TransportInfo) ProtoReflect

func (x *TransportInfo) ProtoReflect() protoreflect.Message

func (*TransportInfo) Reset

func (x *TransportInfo) Reset()

func (*TransportInfo) String

func (x *TransportInfo) String() string

type Tunnel

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

Tunnel creates a request that expects 1..n replies from a remote nats client

type Values

type Values struct {
	Arr []string `protobuf:"bytes,1,rep,name=arr,proto3" json:"arr,omitempty"`
	// contains filtered or unexported fields
}

func (*Values) Descriptor deprecated

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

Deprecated: Use Values.ProtoReflect.Descriptor instead.

func (*Values) GetArr

func (x *Values) GetArr() []string

func (*Values) ProtoMessage

func (*Values) ProtoMessage()

func (*Values) ProtoReflect

func (x *Values) ProtoReflect() protoreflect.Message

func (*Values) Reset

func (x *Values) Reset()

func (*Values) String

func (x *Values) String() string

Jump to

Keyboard shortcuts

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