Documentation
¶
Index ¶
- Variables
- type AllowAllAuthenticator
- type AsyncErrorHandler
- type Client
- func (c *Client) Call(ctx context.Context, subject string, req proto.Message, rsp proto.Message) error
- func (c *Client) CallService(ctx context.Context, service string, req proto.Message, rsp proto.Message) error
- func (c *Client) Notify(ctx context.Context, subject string, msgID uint32, message proto.Message) error
- func (c *Client) NotifyInstance(ctx context.Context, service, instanceID string, msgID uint32, ...) error
- func (c *Client) NotifyMessage(ctx context.Context, subject string, message proto.Message) error
- func (c *Client) NotifyService(ctx context.Context, service string, msgID uint32, message proto.Message) error
- func (c *Client) NotifyServiceMessage(ctx context.Context, service string, message proto.Message) error
- func (c *Client) PublishEnvelope(ctx context.Context, subject string, env *natsrpcv1.Envelope) error
- func (c *Client) Request(ctx context.Context, subject string, msgID uint32, req proto.Message, ...) error
- func (c *Client) RequestEnvelope(ctx context.Context, subject string, env *natsrpcv1.Envelope) (*natsrpcv1.Envelope, error)
- func (c *Client) RequestInstance(ctx context.Context, service, instanceID string, msgID uint32, ...) error
- func (c *Client) RequestService(ctx context.Context, service string, msgID uint32, req proto.Message, ...) error
- type Discovery
- func (d *Discovery) Deregister(ctx context.Context, service, instanceID string) error
- func (d *Discovery) FindInstance(ctx context.Context, service, instanceID string) (ServiceInstance, error)
- func (d *Discovery) Heartbeat(ctx context.Context, service, instanceID string, ttl time.Duration) error
- func (d *Discovery) List(ctx context.Context, service string) ([]ServiceInstance, error)
- func (d *Discovery) Pick(ctx context.Context, service string) (ServiceInstance, error)
- func (d *Discovery) Register(ctx context.Context, instance ServiceInstance, ttl time.Duration) error
- type DiscoveryOption
- type ErrorEncoder
- type NotifyHandler
- type NotifyMessageHandler
- type Option
- func WithAsyncErrorHandler(handler AsyncErrorHandler) Option
- func WithDiscovery(discovery *Discovery) Option
- func WithErrorEncoder(encoder ErrorEncoder) Option
- func WithRegistry(reg *registry.Registry) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTracePropagator(trace TracePropagator) Option
- type RPCHandler
- type RPCMessageHandler
- type RemoteError
- type Router
- func (r *Router) HandleNotify(ctx context.Context, env *natsrpcv1.Envelope) error
- func (r *Router) HandleRPC(ctx context.Context, env *natsrpcv1.Envelope) (*natsrpcv1.Envelope, error)
- func (r *Router) RegisterNotify(msgID uint32, prototype proto.Message, handler NotifyMessageHandler) error
- func (r *Router) RegisterNotifyMessage(prototype proto.Message, handler NotifyMessageHandler) error
- func (r *Router) RegisterRPC(requestID uint32, requestPrototype proto.Message, responseID uint32, ...) error
- func (r *Router) RegisterRPCMessage(requestPrototype proto.Message, responsePrototype proto.Message, ...) error
- func (r *Router) Registry() *registry.Registry
- type Server
- func (s *Server) Close() error
- func (s *Server) QueueSubscribeNotify(ctx context.Context, subject, queue string, handler NotifyHandler) (*Subscription, error)
- func (s *Server) QueueSubscribeRPC(ctx context.Context, subject, queue string, handler RPCHandler) (*Subscription, error)
- func (s *Server) RegisterService(ctx context.Context, discovery *Discovery, instance ServiceInstance, ...) (*ServiceRegistration, error)
- func (s *Server) SubscribeNotify(ctx context.Context, subject string, handler NotifyHandler) (*Subscription, error)
- func (s *Server) SubscribeRPC(ctx context.Context, subject string, handler RPCHandler) (*Subscription, error)
- type ServiceAuthenticator
- type ServiceInstance
- type ServiceRegistration
- type Subscription
- type TracePropagator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoServiceInstances = errors.New("no service instances available")
Functions ¶
This section is empty.
Types ¶
type AllowAllAuthenticator ¶
type AllowAllAuthenticator struct{}
func (AllowAllAuthenticator) AuthorizeRegister ¶
func (AllowAllAuthenticator) AuthorizeRegister(context.Context, ServiceInstance) error
func (AllowAllAuthenticator) AuthorizeResolve ¶
func (AllowAllAuthenticator) AuthorizeResolve(context.Context, string) error
type AsyncErrorHandler ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CallService ¶
func (*Client) NotifyInstance ¶
func (*Client) NotifyMessage ¶
func (*Client) NotifyService ¶
func (*Client) NotifyServiceMessage ¶
func (*Client) PublishEnvelope ¶
func (*Client) RequestEnvelope ¶
func (*Client) RequestInstance ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
func NewDiscovery ¶
func NewDiscovery(conn *nats.Conn, opts ...DiscoveryOption) (*Discovery, error)
func (*Discovery) Deregister ¶
func (*Discovery) FindInstance ¶
type DiscoveryOption ¶
type DiscoveryOption func(*discoveryConfig)
func WithDiscoveryBucket ¶
func WithDiscoveryBucket(bucket string) DiscoveryOption
func WithServiceAuthenticator ¶
func WithServiceAuthenticator(auth ServiceAuthenticator) DiscoveryOption
type ErrorEncoder ¶
type NotifyMessageHandler ¶
type Option ¶
type Option func(*config)
func WithAsyncErrorHandler ¶
func WithAsyncErrorHandler(handler AsyncErrorHandler) Option
func WithDiscovery ¶
func WithErrorEncoder ¶
func WithErrorEncoder(encoder ErrorEncoder) Option
func WithRegistry ¶
func WithTimeout ¶
func WithTracePropagator ¶
func WithTracePropagator(trace TracePropagator) Option
type RPCHandler ¶
type RPCMessageHandler ¶
type RemoteError ¶
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Example (NotifyOneWay) ¶
reg := registry.New()
r := NewRouter(reg)
received := ""
_ = r.RegisterNotify(10, &wrapperspb.StringValue{}, func(_ context.Context, message proto.Message) error {
received = message.(*wrapperspb.StringValue).Value
return nil
})
notify := &natsrpcv1.Envelope{MsgId: 10, Body: mustMarshalForExample(&wrapperspb.StringValue{Value: "hello-notify"})}
_ = r.HandleNotify(context.Background(), notify)
fmt.Println(received)
Output: hello-notify
Example (RpcRequestReply) ¶
reg := registry.New()
r := NewRouter(reg)
_ = r.RegisterRPC(1, &wrapperspb.StringValue{}, 2, &wrapperspb.Int32Value{}, func(_ context.Context, request proto.Message) (proto.Message, error) {
msg := request.(*wrapperspb.StringValue)
return &wrapperspb.Int32Value{Value: int32(len(msg.Value))}, nil
})
req := &natsrpcv1.Envelope{MsgId: 1, RpcId: 101, Body: mustMarshalForExample(&wrapperspb.StringValue{Value: "abcd"})}
resp, _ := r.HandleRPC(context.Background(), req)
out := &wrapperspb.Int32Value{}
_ = proto.Unmarshal(resp.Body, out)
fmt.Println(out.Value)
Output: 4
func (*Router) HandleNotify ¶
func (*Router) RegisterNotify ¶
func (*Router) RegisterNotifyMessage ¶
func (r *Router) RegisterNotifyMessage(prototype proto.Message, handler NotifyMessageHandler) error
func (*Router) RegisterRPC ¶
func (*Router) RegisterRPCMessage ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) QueueSubscribeNotify ¶
func (s *Server) QueueSubscribeNotify(ctx context.Context, subject, queue string, handler NotifyHandler) (*Subscription, error)
func (*Server) QueueSubscribeRPC ¶
func (s *Server) QueueSubscribeRPC(ctx context.Context, subject, queue string, handler RPCHandler) (*Subscription, error)
func (*Server) RegisterService ¶
func (*Server) SubscribeNotify ¶
func (s *Server) SubscribeNotify(ctx context.Context, subject string, handler NotifyHandler) (*Subscription, error)
func (*Server) SubscribeRPC ¶
func (s *Server) SubscribeRPC(ctx context.Context, subject string, handler RPCHandler) (*Subscription, error)
type ServiceAuthenticator ¶
type ServiceInstance ¶
type ServiceInstance struct {
Service string `json:"service"`
InstanceID string `json:"instance_id"`
Subject string `json:"subject"`
Version string `json:"version,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
HeartbeatAt time.Time `json:"heartbeat_at"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
}
type ServiceRegistration ¶
type ServiceRegistration struct {
// contains filtered or unexported fields
}
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.