Documentation
¶
Index ¶
- Constants
- func GetHeaders(ctx context.Context) (nats.Header, bool)
- func GetSubject(ctx context.Context) (service.Subject, bool)
- type ClientConn
- type MockPublisher
- func (_m *MockPublisher) EXPECT() *MockPublisher_Expecter
- func (_m *MockPublisher) PublishTo(msg protoreflect.ProtoMessage, tokens ...string) error
- func (_m *MockPublisher) RequestFrom(ctx context.Context, msg protoreflect.ProtoMessage, ...) (service.Message, error)
- func (_m *MockPublisher) Serve(handler service.ServiceHandler, suffixes ...string) (*nats.Subscription, error)
- func (_m *MockPublisher) Subject(suffixes ...string) string
- func (_m *MockPublisher) SubscribeTo(handler service.MessageHandler, tokens ...string) (*nats.Subscription, error)
- func (_m *MockPublisher) Unmarshal(nmsg service.Message, msg protoreflect.ProtoMessage) (nats.Header, error)
- type MockPublisher_Expecter
- func (_e *MockPublisher_Expecter) PublishTo(msg interface{}, tokens ...interface{}) *MockPublisher_PublishTo_Call
- func (_e *MockPublisher_Expecter) RequestFrom(ctx interface{}, msg interface{}, resp interface{}, tokens ...interface{}) *MockPublisher_RequestFrom_Call
- func (_e *MockPublisher_Expecter) Serve(handler interface{}, suffixes ...interface{}) *MockPublisher_Serve_Call
- func (_e *MockPublisher_Expecter) Subject(suffixes ...interface{}) *MockPublisher_Subject_Call
- func (_e *MockPublisher_Expecter) SubscribeTo(handler interface{}, tokens ...interface{}) *MockPublisher_SubscribeTo_Call
- func (_e *MockPublisher_Expecter) Unmarshal(nmsg interface{}, msg interface{}) *MockPublisher_Unmarshal_Call
- type MockPublisher_PublishTo_Call
- func (_c *MockPublisher_PublishTo_Call) Return(_a0 error) *MockPublisher_PublishTo_Call
- func (_c *MockPublisher_PublishTo_Call) Run(run func(msg protoreflect.ProtoMessage, tokens ...string)) *MockPublisher_PublishTo_Call
- func (_c *MockPublisher_PublishTo_Call) RunAndReturn(run func(protoreflect.ProtoMessage, ...string) error) *MockPublisher_PublishTo_Call
- type MockPublisher_RequestFrom_Call
- func (_c *MockPublisher_RequestFrom_Call) Return(_a0 service.Message, _a1 error) *MockPublisher_RequestFrom_Call
- func (_c *MockPublisher_RequestFrom_Call) Run(run func(ctx context.Context, msg protoreflect.ProtoMessage, ...)) *MockPublisher_RequestFrom_Call
- func (_c *MockPublisher_RequestFrom_Call) RunAndReturn(...) *MockPublisher_RequestFrom_Call
- type MockPublisher_Serve_Call
- func (_c *MockPublisher_Serve_Call) Return(_a0 *nats.Subscription, _a1 error) *MockPublisher_Serve_Call
- func (_c *MockPublisher_Serve_Call) Run(run func(handler service.ServiceHandler, suffixes ...string)) *MockPublisher_Serve_Call
- func (_c *MockPublisher_Serve_Call) RunAndReturn(run func(service.ServiceHandler, ...string) (*nats.Subscription, error)) *MockPublisher_Serve_Call
- type MockPublisher_Subject_Call
- type MockPublisher_SubscribeTo_Call
- func (_c *MockPublisher_SubscribeTo_Call) Return(_a0 *nats.Subscription, _a1 error) *MockPublisher_SubscribeTo_Call
- func (_c *MockPublisher_SubscribeTo_Call) Run(run func(handler service.MessageHandler, tokens ...string)) *MockPublisher_SubscribeTo_Call
- func (_c *MockPublisher_SubscribeTo_Call) RunAndReturn(run func(service.MessageHandler, ...string) (*nats.Subscription, error)) *MockPublisher_SubscribeTo_Call
- type MockPublisher_Unmarshal_Call
- func (_c *MockPublisher_Unmarshal_Call) Return(_a0 nats.Header, _a1 error) *MockPublisher_Unmarshal_Call
- func (_c *MockPublisher_Unmarshal_Call) Run(run func(nmsg service.Message, msg protoreflect.ProtoMessage)) *MockPublisher_Unmarshal_Call
- func (_c *MockPublisher_Unmarshal_Call) RunAndReturn(run func(service.Message, protoreflect.ProtoMessage) (nats.Header, error)) *MockPublisher_Unmarshal_Call
- type Publisher
- type ServiceRegistrar
Constants ¶
const ( HeaderContextKey serviceKey = "headers" SubjectContextKey serviceKey = "subject" )
Variables ¶
This section is empty.
Functions ¶
func GetHeaders ¶
Types ¶
type ClientConn ¶
type ClientConn struct {
// contains filtered or unexported fields
}
ClientConn implements grpc.ClientConnInterface for NATS
func NewClientConn ¶
func NewClientConn(ctx context.Context, sub Publisher, remotePrefix string, vars map[string]string) *ClientConn
NewClientConn returns a client connector that functions as a layer between Protobuf Auto-generated gRPC client code and Data Layer allowing making rpc calls to a remote publisher.
It automatically derives the correct subjects based on the Protobuf schema, however, you may need to specify the remote prefix that the publisher is configured with. Also, you may need to pass vars. The subjects derived if contain any tokens such as `{id}`, will be substituted by the string stored under key "id". Otherwise such subject token will be replaced with `*`.
Naturally such subjects are invalid for a rpc call, so you must always supply variables for a client. Consuming pure streams will work just fine.
func (*ClientConn) Invoke ¶
func (c *ClientConn) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error
func (*ClientConn) NewStream ¶
func (c *ClientConn) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
type MockPublisher ¶
MockPublisher is an autogenerated mock type for the Publisher type
func NewMockPublisher ¶
func NewMockPublisher(t interface { mock.TestingT Cleanup(func()) }) *MockPublisher
NewMockPublisher creates a new instance of MockPublisher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockPublisher) EXPECT ¶
func (_m *MockPublisher) EXPECT() *MockPublisher_Expecter
func (*MockPublisher) PublishTo ¶
func (_m *MockPublisher) PublishTo(msg protoreflect.ProtoMessage, tokens ...string) error
PublishTo provides a mock function with given fields: msg, tokens
func (*MockPublisher) RequestFrom ¶
func (_m *MockPublisher) RequestFrom(ctx context.Context, msg protoreflect.ProtoMessage, resp protoreflect.ProtoMessage, tokens ...string) (service.Message, error)
RequestFrom provides a mock function with given fields: ctx, msg, resp, tokens
func (*MockPublisher) Serve ¶
func (_m *MockPublisher) Serve(handler service.ServiceHandler, suffixes ...string) (*nats.Subscription, error)
Serve provides a mock function with given fields: handler, suffixes
func (*MockPublisher) Subject ¶
func (_m *MockPublisher) Subject(suffixes ...string) string
Subject provides a mock function with given fields: suffixes
func (*MockPublisher) SubscribeTo ¶
func (_m *MockPublisher) SubscribeTo(handler service.MessageHandler, tokens ...string) (*nats.Subscription, error)
SubscribeTo provides a mock function with given fields: handler, tokens
func (*MockPublisher) Unmarshal ¶
func (_m *MockPublisher) Unmarshal(nmsg service.Message, msg protoreflect.ProtoMessage) (nats.Header, error)
Unmarshal provides a mock function with given fields: nmsg, msg
type MockPublisher_Expecter ¶
type MockPublisher_Expecter struct {
// contains filtered or unexported fields
}
func (*MockPublisher_Expecter) PublishTo ¶
func (_e *MockPublisher_Expecter) PublishTo(msg interface{}, tokens ...interface{}) *MockPublisher_PublishTo_Call
PublishTo is a helper method to define mock.On call
- msg protoreflect.ProtoMessage
- tokens ...string
func (*MockPublisher_Expecter) RequestFrom ¶
func (_e *MockPublisher_Expecter) RequestFrom(ctx interface{}, msg interface{}, resp interface{}, tokens ...interface{}) *MockPublisher_RequestFrom_Call
RequestFrom is a helper method to define mock.On call
- ctx context.Context
- msg protoreflect.ProtoMessage
- resp protoreflect.ProtoMessage
- tokens ...string
func (*MockPublisher_Expecter) Serve ¶
func (_e *MockPublisher_Expecter) Serve(handler interface{}, suffixes ...interface{}) *MockPublisher_Serve_Call
Serve is a helper method to define mock.On call
- handler service.ServiceHandler
- suffixes ...string
func (*MockPublisher_Expecter) Subject ¶
func (_e *MockPublisher_Expecter) Subject(suffixes ...interface{}) *MockPublisher_Subject_Call
Subject is a helper method to define mock.On call
- suffixes ...string
func (*MockPublisher_Expecter) SubscribeTo ¶
func (_e *MockPublisher_Expecter) SubscribeTo(handler interface{}, tokens ...interface{}) *MockPublisher_SubscribeTo_Call
SubscribeTo is a helper method to define mock.On call
- handler service.MessageHandler
- tokens ...string
func (*MockPublisher_Expecter) Unmarshal ¶
func (_e *MockPublisher_Expecter) Unmarshal(nmsg interface{}, msg interface{}) *MockPublisher_Unmarshal_Call
Unmarshal is a helper method to define mock.On call
- nmsg service.Message
- msg protoreflect.ProtoMessage
type MockPublisher_PublishTo_Call ¶
MockPublisher_PublishTo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PublishTo'
func (*MockPublisher_PublishTo_Call) Return ¶
func (_c *MockPublisher_PublishTo_Call) Return(_a0 error) *MockPublisher_PublishTo_Call
func (*MockPublisher_PublishTo_Call) Run ¶
func (_c *MockPublisher_PublishTo_Call) Run(run func(msg protoreflect.ProtoMessage, tokens ...string)) *MockPublisher_PublishTo_Call
func (*MockPublisher_PublishTo_Call) RunAndReturn ¶
func (_c *MockPublisher_PublishTo_Call) RunAndReturn(run func(protoreflect.ProtoMessage, ...string) error) *MockPublisher_PublishTo_Call
type MockPublisher_RequestFrom_Call ¶
MockPublisher_RequestFrom_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestFrom'
func (*MockPublisher_RequestFrom_Call) Return ¶
func (_c *MockPublisher_RequestFrom_Call) Return(_a0 service.Message, _a1 error) *MockPublisher_RequestFrom_Call
func (*MockPublisher_RequestFrom_Call) Run ¶
func (_c *MockPublisher_RequestFrom_Call) Run(run func(ctx context.Context, msg protoreflect.ProtoMessage, resp protoreflect.ProtoMessage, tokens ...string)) *MockPublisher_RequestFrom_Call
func (*MockPublisher_RequestFrom_Call) RunAndReturn ¶
func (_c *MockPublisher_RequestFrom_Call) RunAndReturn(run func(context.Context, protoreflect.ProtoMessage, protoreflect.ProtoMessage, ...string) (service.Message, error)) *MockPublisher_RequestFrom_Call
type MockPublisher_Serve_Call ¶
MockPublisher_Serve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Serve'
func (*MockPublisher_Serve_Call) Return ¶
func (_c *MockPublisher_Serve_Call) Return(_a0 *nats.Subscription, _a1 error) *MockPublisher_Serve_Call
func (*MockPublisher_Serve_Call) Run ¶
func (_c *MockPublisher_Serve_Call) Run(run func(handler service.ServiceHandler, suffixes ...string)) *MockPublisher_Serve_Call
func (*MockPublisher_Serve_Call) RunAndReturn ¶
func (_c *MockPublisher_Serve_Call) RunAndReturn(run func(service.ServiceHandler, ...string) (*nats.Subscription, error)) *MockPublisher_Serve_Call
type MockPublisher_Subject_Call ¶
MockPublisher_Subject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subject'
func (*MockPublisher_Subject_Call) Return ¶
func (_c *MockPublisher_Subject_Call) Return(_a0 string) *MockPublisher_Subject_Call
func (*MockPublisher_Subject_Call) Run ¶
func (_c *MockPublisher_Subject_Call) Run(run func(suffixes ...string)) *MockPublisher_Subject_Call
func (*MockPublisher_Subject_Call) RunAndReturn ¶
func (_c *MockPublisher_Subject_Call) RunAndReturn(run func(...string) string) *MockPublisher_Subject_Call
type MockPublisher_SubscribeTo_Call ¶
MockPublisher_SubscribeTo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SubscribeTo'
func (*MockPublisher_SubscribeTo_Call) Return ¶
func (_c *MockPublisher_SubscribeTo_Call) Return(_a0 *nats.Subscription, _a1 error) *MockPublisher_SubscribeTo_Call
func (*MockPublisher_SubscribeTo_Call) Run ¶
func (_c *MockPublisher_SubscribeTo_Call) Run(run func(handler service.MessageHandler, tokens ...string)) *MockPublisher_SubscribeTo_Call
func (*MockPublisher_SubscribeTo_Call) RunAndReturn ¶
func (_c *MockPublisher_SubscribeTo_Call) RunAndReturn(run func(service.MessageHandler, ...string) (*nats.Subscription, error)) *MockPublisher_SubscribeTo_Call
type MockPublisher_Unmarshal_Call ¶
MockPublisher_Unmarshal_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unmarshal'
func (*MockPublisher_Unmarshal_Call) Return ¶
func (_c *MockPublisher_Unmarshal_Call) Return(_a0 nats.Header, _a1 error) *MockPublisher_Unmarshal_Call
func (*MockPublisher_Unmarshal_Call) Run ¶
func (_c *MockPublisher_Unmarshal_Call) Run(run func(nmsg service.Message, msg protoreflect.ProtoMessage)) *MockPublisher_Unmarshal_Call
func (*MockPublisher_Unmarshal_Call) RunAndReturn ¶
func (_c *MockPublisher_Unmarshal_Call) RunAndReturn(run func(service.Message, protoreflect.ProtoMessage) (nats.Header, error)) *MockPublisher_Unmarshal_Call
type Publisher ¶
type Publisher interface { Serve(handler service.ServiceHandler, suffixes ...string) (*nats.Subscription, error) RequestFrom(ctx context.Context, msg proto.Message, resp proto.Message, tokens ...string) (service.Message, error) SubscribeTo(handler service.MessageHandler, tokens ...string) (*nats.Subscription, error) PublishTo(msg proto.Message, tokens ...string) error PublishToRpc(msg proto.Message, replyTo string, tokens ...string) error RpcInbox(suffixes ...string) string Unmarshal(nmsg service.Message, msg protoreflect.ProtoMessage) (nats.Header, error) Subject(suffixes ...string) string }
Publisher interface from your NATS wrapper
type ServiceRegistrar ¶
type ServiceRegistrar struct {
// contains filtered or unexported fields
}
ServiceRegistrar implements grpc.ServiceRegistrar for NATS
func NewServiceRegistrar ¶
func NewServiceRegistrar(group *errgroup.Group, pub Publisher) *ServiceRegistrar
func (*ServiceRegistrar) RegisterService ¶
func (s *ServiceRegistrar) RegisterService(desc *grpc.ServiceDesc, impl interface{})
RegisterService is called by the autogenerated Protobuf service code.
func (*ServiceRegistrar) Start ¶
Start begins processing service events, subscribes to rpc subjects, and calls pure-stream methods on a service.
It automatically derives the correct subjects based on the Protobuf schema, however, you may need to pass vars. The subjects derived if contain any tokens such as `{id}` will be substituted by the string stored under key "id" under a specific service key. Otherwise such subject token will be replaced with `*`.
You can also specify the full name of the service and the variable using fully qualified name of the service if more than one service shares the same variable.