Documentation
¶
Overview ¶
Package natsclient provides NATS messaging infrastructure. This framework exclusively supports int64 RoleID for user identification.
Index ¶
- func NatsCheckMsg(data []byte) *berror.ErrMsg
- func NatsMarshalAppend(b *objectpool.Bytes, msg proto.Message) *berror.ErrMsg
- func NatsMarshalManyAppend(b *objectpool.Bytes, msgS ...proto.Message) *berror.ErrMsg
- func NatsMarshalManySize(msgS ...proto.Message) (int, *berror.ErrMsg)
- func NatsMarshalSize(msg proto.Message) (int, *berror.ErrMsg)
- func NatsMsgReply(reply *nats.Msg, isRespFirst bool, resp proto.Message, ...) *berror.ErrMsg
- func NatsMsgReplyError(reply *nats.Msg, err *berror.ErrMsg) *berror.ErrMsg
- func NatsParseUserMsgRaw(data []byte) ([]byte, []byte)
- func NatsUnmarshalResponse(data []byte) (string, []byte, *berror.ErrMsg)
- func NatsUnmarshalResponseMany(data []byte, f func(string, []byte) *berror.ErrMsg) *berror.ErrMsg
- func NatsUnmarshalResponseWithout(d []byte, respMsg proto.Message) *berror.ErrMsg
- type ClientPublish
- type ClientPublishServerUser
- type ClientRequest
- func (r *ClientRequest[T, T1, REQ, RESP]) Free()
- func (r *ClientRequest[T, T1, REQ, RESP]) Request(nc *NatsClient, c ctx.IContext) *berror.ErrMsg
- func (r *ClientRequest[T, T1, REQ, RESP]) RequestToServer(nc *NatsClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
- func (r *ClientRequest[T, T1, REQ, RESP]) Reset()
- type ClientRequestServerUser
- type ClusterClient
- func (this_ *ClusterClient) Close()
- func (this_ *ClusterClient) Publish(c ctx.IContext, pubMsg proto.Message) *berror.ErrMsg
- func (this_ *ClusterClient) PublishRawData(c ctx.IContext, toServerId int64, pubMsgName string, pubMsgData []byte) *berror.ErrMsg
- func (this_ *ClusterClient) PublishToServer(c ctx.IContext, toServerId int64, pubMsg proto.Message) *berror.ErrMsg
- func (this_ *ClusterClient) QueueSubscribeAll(subj string, h nats.MsgHandler)
- func (this_ *ClusterClient) QueueSubscribeAllWaitSuccess(subj string, h nats.MsgHandler)
- func (this_ *ClusterClient) Request(c ctx.IContext, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
- func (this_ *ClusterClient) RequestRaw(c ctx.IContext, toServerId int64, reqMsgName string, reqMsgData []byte) ([]byte, *berror.ErrMsg)
- func (this_ *ClusterClient) RequestToServer(c ctx.IContext, toServerId int64, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
- func (this_ *ClusterClient) Shutdown()
- func (this_ *ClusterClient) SubscribeAll(subj string, h nats.MsgHandler)
- func (this_ *ClusterClient) SubscribeAllWaitSuccess(subj string, h nats.MsgHandler)
- func (this_ *ClusterClient) Unsubscribe(subj string)
- type ClusterClientServerUser
- func NewClusterClientServerUser[T any, US ServerUserSubjectPtr[T]](urls []string, rpcTimeout time.Duration, userHandler nats.MsgHandler, ...) *ClusterClientServerUser[T, US]
- func NewClusterClientServerUser2[T any, US ServerUserSubjectPtr[T]](cnc *ClusterClient, userHandler nats.MsgHandler, opts ...UNOption) *ClusterClientServerUser[T, US]
- func (cnc *ClusterClientServerUser[T, US]) Close()
- func (cnc *ClusterClientServerUser[T, US]) PublishUser(c ctx.IContext, us US, pubMsg proto.Message) *berror.ErrMsg
- func (cnc *ClusterClientServerUser[T, US]) PublishUserMany(c ctx.IContext, us US, pubMsg ...proto.Message) *berror.ErrMsg
- func (cnc *ClusterClientServerUser[T, US]) RequestUser(c ctx.IContext, us US, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
- func (cnc *ClusterClientServerUser[T, US]) UserSubscribeAll(us US)
- func (cnc *ClusterClientServerUser[T, US]) UserSubscribeAllWaitSuccess(us US)
- func (cnc *ClusterClientServerUser[T, US]) UserSubscribeOne(us US)
- func (cnc *ClusterClientServerUser[T, US]) UserSubscribeOneWaitSuccess(us US)
- func (cnc *ClusterClientServerUser[T, US]) UserUnsubscribe(us US)
- type ClusterPublish
- type ClusterPublishServerUser
- type ClusterRequest
- func (r *ClusterRequest[T, T1, REQ, RESP]) Free()
- func (r *ClusterRequest[T, T1, REQ, RESP]) Request(cnc *ClusterClient, c ctx.IContext) *berror.ErrMsg
- func (r *ClusterRequest[T, T1, REQ, RESP]) RequestToServer(cnc *ClusterClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
- func (r *ClusterRequest[T, T1, REQ, RESP]) Reset()
- type ClusterRequestServerUser
- type NatsClient
- func (this_ *NatsClient) Close()
- func (this_ *NatsClient) Conn() *nats.Conn
- func (this_ *NatsClient) Publish(c ctx.IContext, pubMsg proto.Message) *berror.ErrMsg
- func (this_ *NatsClient) PublishRawData(c ctx.IContext, toServerId int64, msgName string, msgData []byte) *berror.ErrMsg
- func (this_ *NatsClient) PublishToServer(c ctx.IContext, toServerId int64, pubMsg proto.Message) *berror.ErrMsg
- func (this_ *NatsClient) QueueSubscribe(subj string, h nats.MsgHandler) bool
- func (this_ *NatsClient) QueueSubscribeWaitSuccess(subj string, h nats.MsgHandler) bool
- func (this_ *NatsClient) Request(c ctx.IContext, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
- func (this_ *NatsClient) RequestRaw(c ctx.IContext, toServerId int64, reqMsgName string, reqMsgData []byte) ([]byte, *berror.ErrMsg)
- func (this_ *NatsClient) RequestToServer(c ctx.IContext, toServerId int64, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
- func (this_ *NatsClient) Shutdown()
- func (this_ *NatsClient) Subscribe(subj string, h nats.MsgHandler) bool
- func (this_ *NatsClient) SubscribeWaitSuccess(subj string, h nats.MsgHandler) bool
- func (this_ *NatsClient) Unsubscribe(subj string)
- type ServerIntUserSubject
- type ServerUserNatsClient
- func (nc *ServerUserNatsClient[T, US]) Close()
- func (nc *ServerUserNatsClient[T, US]) PublishUser(c ctx.IContext, us US, pubMsg proto.Message) *berror.ErrMsg
- func (nc *ServerUserNatsClient[T, US]) PublishUserMany(c ctx.IContext, us US, pubMsg ...proto.Message) *berror.ErrMsg
- func (nc *ServerUserNatsClient[T, US]) QueueSubscribeUser(us US, handler nats.MsgHandler) bool
- func (nc *ServerUserNatsClient[T, US]) QueueSubscribeUserWaitSuccess(us US) bool
- func (nc *ServerUserNatsClient[T, US]) RequestUser(c ctx.IContext, us US, reqMsg proto.Message, out proto.Message) *berror.ErrMsg
- func (nc *ServerUserNatsClient[T, US]) SubscribeUser(us US) bool
- func (nc *ServerUserNatsClient[T, US]) SubscribeUserWaitSuccess(us US) bool
- func (nc *ServerUserNatsClient[T, US]) UnsubscribeUser(us US)
- type ServerUserSubject
- type ServerUserSubjectPtr
- type UNOption
- type UNOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NatsCheckMsg ¶ added in v0.1.9
func NatsMarshalAppend ¶ added in v0.1.8
func NatsMarshalManyAppend ¶ added in v0.1.8
func NatsMarshalManySize ¶ added in v0.1.8
func NatsMarshalSize ¶ added in v0.1.8
func NatsMsgReply ¶
func NatsMsgReply(reply *nats.Msg, isRespFirst bool, resp proto.Message, otherResp ...proto.Message) *berror.ErrMsg
NatsMsgReply sends resp and optional otherResp back to the caller. When isRespFirst is true resp is serialized before otherResp; otherwise otherResp comes first and resp is appended last. No intermediate slice is allocated: size is computed in two passes and the buffer is written in order.
func NatsMsgReplyError ¶
NatsMsgReplyError Reply to nats.Msg for an *berror.ErrMsg
func NatsParseUserMsgRaw ¶ added in v0.1.9
func NatsUnmarshalResponse ¶ added in v0.1.8
func NatsUnmarshalResponseMany ¶ added in v0.1.9
Types ¶
type ClientPublish ¶
type ClientPublish[T any, PUB define.ProtoMessagePtr[T]] struct { Pub T define.DoNotCopy }
ClientPublish publish for topic designed to use objectpool, because Pub will always escape to heap for more information, see NatsClient.Publish and NatsClient.PublishToServer create use NewClientPublish
func NewClientPublish ¶
func NewClientPublish[T any, PUB define.ProtoMessagePtr[T]]() *ClientPublish[T, PUB]
NewClientPublish create a ClientPublish from objectpool
func (*ClientPublish[T, PUB]) Free ¶
func (r *ClientPublish[T, PUB]) Free()
Free object to objectpool
func (*ClientPublish[T, PUB]) Publish ¶
func (r *ClientPublish[T, PUB]) Publish(nc *NatsClient, c ctx.IContext) *berror.ErrMsg
Publish msg to serverId is 0 or a cluster server node more information, see NatsClient.Publish and NatsClient.PublishToServer
func (*ClientPublish[T, PUB]) PublishToServer ¶
func (r *ClientPublish[T, PUB]) PublishToServer(nc *NatsClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
PublishToServer publish msg to specified server instance of toServerId more information, see NatsClient.Publish and NatsClient.PublishToServer
func (*ClientPublish[T, PUB]) Reset ¶
func (r *ClientPublish[T, PUB]) Reset()
Reset implement define.Clear
type ClientPublishServerUser ¶
type ClientPublishServerUser[T, T1 any, US ServerUserSubjectPtr[T], PUB define.ProtoMessagePtr[T1]] struct { Pub T1 Us T define.DoNotCopy }
ClientPublishServerUser publish msg to user topic designed to use objectpool, because Pub,Us will always escape to heap for more information, see NatsClient.PublishServerUser create use NewSUClientPublishUser
func NewSUClientPublishUser ¶
func NewSUClientPublishUser[T, T1 any, US ServerUserSubjectPtr[T], PUB define.ProtoMessagePtr[T1]]() *ClientPublishServerUser[T, T1, US, PUB]
NewSUClientPublishUser create ClientPublishServerUser for objectpool
func (*ClientPublishServerUser[T, T1, US, PUB]) Free ¶
func (r *ClientPublishServerUser[T, T1, US, PUB]) Free()
func (*ClientPublishServerUser[T, T1, US, PUB]) Publish ¶
func (r *ClientPublishServerUser[T, T1, US, PUB]) Publish(nc *ServerUserNatsClient[T, US], c ctx.IContext) *berror.ErrMsg
Publish more info see NatsClient.PublishServerUser
func (*ClientPublishServerUser[T, T1, US, PUB]) Reset ¶
func (r *ClientPublishServerUser[T, T1, US, PUB]) Reset()
Reset implement define.Clear
type ClientRequest ¶
type ClientRequest[T, T1 any, REQ define.ProtoMessagePtr[T], RESP define.ProtoMessagePtr[T1]] struct { Req T Resp T1 define.DoNotCopy }
ClientRequest rpc for topic designed to use objectpool, because Req, Resp will always escape to heap for more information, see NatsClient.Request create use NewClientRequest
func NewClientRequest ¶
func NewClientRequest[T, T1 any, REQ define.ProtoMessagePtr[T], RESP define.ProtoMessagePtr[T1]]() *ClientRequest[T, T1, REQ, RESP]
NewClientRequest create ClientRequest for objectpool
func (*ClientRequest[T, T1, REQ, RESP]) Free ¶
func (r *ClientRequest[T, T1, REQ, RESP]) Free()
func (*ClientRequest[T, T1, REQ, RESP]) Request ¶
func (r *ClientRequest[T, T1, REQ, RESP]) Request(nc *NatsClient, c ctx.IContext) *berror.ErrMsg
Request more info see NatsClient.Request
func (*ClientRequest[T, T1, REQ, RESP]) RequestToServer ¶
func (r *ClientRequest[T, T1, REQ, RESP]) RequestToServer(nc *NatsClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
RequestToServer more info see NatsClient.RequestToServer
func (*ClientRequest[T, T1, REQ, RESP]) Reset ¶
func (r *ClientRequest[T, T1, REQ, RESP]) Reset()
Reset implement define.Clear
type ClientRequestServerUser ¶
type ClientRequestServerUser[T, T1, T2 any, US ServerUserSubjectPtr[T], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2]] struct { Req T1 Resp T2 Us T define.DoNotCopy }
ClientRequestServerUser rpc user topic designed to use objectpool, because Pub,Us will always escape to heap for more information, see NatsClient.RequestUser create use NewClientRequestServerUser
func NewClientRequestServerUser ¶
func NewClientRequestServerUser[T, T1, T2 any, US ServerUserSubjectPtr[T], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2]]() *ClientRequestServerUser[T, T1, T2, US, REQ, RESP]
NewClientRequestServerUser create ClientRequestServerUser for objectpool
func (*ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Free ¶
func (r *ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Free()
func (*ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Request ¶
func (r *ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Request(nc *ServerUserNatsClient[T, US], c ctx.IContext) *berror.ErrMsg
Request more info see NatsClient.Request
func (*ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Reset ¶
func (r *ClientRequestServerUser[T, T1, T2, US, REQ, RESP]) Reset()
Reset implement define.Clear
type ClusterClient ¶
type ClusterClient struct {
// contains filtered or unexported fields
}
func NewClusterClient ¶
func NewClusterClient(urls []string, rpcTimeout time.Duration, options ...nats.Option) *ClusterClient
NewClusterClient create a ClusterClient encapsulates the calling design of the entire framework param name Usually the server name ( baseenv.Config.ServerType ) param urls a nats cluster urls param timeout for request
func (*ClusterClient) Publish ¶
Publish more info see NatsClient.Publish recommended use ClusterPublish.Publish
func (*ClusterClient) PublishRawData ¶
func (this_ *ClusterClient) PublishRawData(c ctx.IContext, toServerId int64, pubMsgName string, pubMsgData []byte) *berror.ErrMsg
PublishRawData more info see NatsClient.PublishRawData
func (*ClusterClient) PublishToServer ¶
func (this_ *ClusterClient) PublishToServer(c ctx.IContext, toServerId int64, pubMsg proto.Message) *berror.ErrMsg
PublishToServer more info see NatsClient.PublishToServer recommended use ClusterPublish.PublishToServer
func (*ClusterClient) QueueSubscribeAll ¶
func (this_ *ClusterClient) QueueSubscribeAll(subj string, h nats.MsgHandler)
QueueSubscribeAll queue subscribe subj for all NatsClient if not subscribed.
func (*ClusterClient) QueueSubscribeAllWaitSuccess ¶
func (this_ *ClusterClient) QueueSubscribeAllWaitSuccess(subj string, h nats.MsgHandler)
QueueSubscribeAllWaitSuccess queue subscribe subj for all NatsClient if not subscribed and wait success.
func (*ClusterClient) Request ¶
func (this_ *ClusterClient) Request(c ctx.IContext, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
Request rpc with ClusterClient. param reqMsg, respMsg escapes to heap. more info see NatsClient.Request recommended use ClusterRequest.Request
func (*ClusterClient) RequestRaw ¶
func (this_ *ClusterClient) RequestRaw(c ctx.IContext, toServerId int64, reqMsgName string, reqMsgData []byte) ([]byte, *berror.ErrMsg)
RequestRaw rpc with raw data for one NatsClient. param if toServerId==0, Receiver serverId is 0 or a cluster server node param reqMsgName is proto message name. param reqMsgData is proto message data. return nats.Msg.Ctx and berror.ErrMsg.
func (*ClusterClient) RequestToServer ¶
func (this_ *ClusterClient) RequestToServer(c ctx.IContext, toServerId int64, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
RequestToServer rpc with raw data for one NatsClient. param if toServerId==0, Receiver serverId is 0 or a cluster server node param reqMsg, respMsg escapes to heap. more info see NatsClient.RequestToServer recommended use ClusterRequest.RequestToServer
func (*ClusterClient) SubscribeAll ¶
func (this_ *ClusterClient) SubscribeAll(subj string, h nats.MsgHandler)
SubscribeAll subscribe subj for all NatsClient if not subscribed.
func (*ClusterClient) SubscribeAllWaitSuccess ¶
func (this_ *ClusterClient) SubscribeAllWaitSuccess(subj string, h nats.MsgHandler)
SubscribeAllWaitSuccess subscribe subj for all NatsClient if not subscribed and wait success.
func (*ClusterClient) Unsubscribe ¶
func (this_ *ClusterClient) Unsubscribe(subj string)
Unsubscribe unsubscribe subj for all NatsClient if subscribed.
type ClusterClientServerUser ¶
type ClusterClientServerUser[T any, US ServerUserSubjectPtr[T]] struct { *ClusterClient // contains filtered or unexported fields }
ClusterClientServerUser is a ClusterClient with user topic
func NewClusterClientServerUser ¶
func NewClusterClientServerUser[T any, US ServerUserSubjectPtr[T]]( urls []string, rpcTimeout time.Duration, userHandler nats.MsgHandler, opts ...UNOption, ) *ClusterClientServerUser[T, US]
NewClusterClientServerUser create a ClusterClientServerUser.
func NewClusterClientServerUser2 ¶
func NewClusterClientServerUser2[T any, US ServerUserSubjectPtr[T]]( cnc *ClusterClient, userHandler nats.MsgHandler, opts ...UNOption, ) *ClusterClientServerUser[T, US]
func (*ClusterClientServerUser[T, US]) Close ¶ added in v0.1.3
func (cnc *ClusterClientServerUser[T, US]) Close()
func (*ClusterClientServerUser[T, US]) PublishUser ¶
func (cnc *ClusterClientServerUser[T, US]) PublishUser(c ctx.IContext, us US, pubMsg proto.Message) *berror.ErrMsg
PublishUser Publish msg user topic for one NatsClient. param us,pubMsg escapes to heap. recommended use ClusterPublishServerUser
func (*ClusterClientServerUser[T, US]) PublishUserMany ¶ added in v0.1.9
func (*ClusterClientServerUser[T, US]) RequestUser ¶
func (cnc *ClusterClientServerUser[T, US]) RequestUser(c ctx.IContext, us US, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
RequestUser Request msg user topic for one NatsClient. param us, reqMsg, respMsg escapes to heap. recommended use ClusterRequestServerUser
func (*ClusterClientServerUser[T, US]) UserSubscribeAll ¶
func (cnc *ClusterClientServerUser[T, US]) UserSubscribeAll(us US)
UserSubscribeAll Subscribe user topic for all NatsClient. param us not escapes to heap.
func (*ClusterClientServerUser[T, US]) UserSubscribeAllWaitSuccess ¶
func (cnc *ClusterClientServerUser[T, US]) UserSubscribeAllWaitSuccess(us US)
UserSubscribeAllWaitSuccess Subscribe user topic for all NatsClient and wait success.
func (*ClusterClientServerUser[T, US]) UserSubscribeOne ¶
func (cnc *ClusterClientServerUser[T, US]) UserSubscribeOne(us US)
UserSubscribeOne Subscribe user topic for one NatsClient. param us not escapes to heap.
func (*ClusterClientServerUser[T, US]) UserSubscribeOneWaitSuccess ¶
func (cnc *ClusterClientServerUser[T, US]) UserSubscribeOneWaitSuccess(us US)
UserSubscribeOneWaitSuccess Subscribe user topic for one NatsClient and wait success.
func (*ClusterClientServerUser[T, US]) UserUnsubscribe ¶
func (cnc *ClusterClientServerUser[T, US]) UserUnsubscribe(us US)
UserUnsubscribe Unsubscribe user topic for all NatsClient if subscribed. param us not escapes to heap.
type ClusterPublish ¶
type ClusterPublish[T any, PUB define.ProtoMessagePtr[T]] struct { Pub T define.DoNotCopy }
ClusterPublish publish message with ClusterClient.
func NewClusterPublish ¶
func NewClusterPublish[T any, PUB define.ProtoMessagePtr[T]]() *ClusterPublish[T, PUB]
NewClusterPublish create a ClusterPublish use objectpool ClusterPublish just can only be used once
func (*ClusterPublish[T, PUB]) Free ¶
func (r *ClusterPublish[T, PUB]) Free()
func (*ClusterPublish[T, PUB]) Publish ¶
func (r *ClusterPublish[T, PUB]) Publish(cnc *ClusterClient, c ctx.IContext) *berror.ErrMsg
Publish more info see ClusterClient.Publish
func (*ClusterPublish[T, PUB]) PublishToServer ¶
func (r *ClusterPublish[T, PUB]) PublishToServer(cnc *ClusterClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
PublishToServer more info see ClusterClient.PublishToServer
func (*ClusterPublish[T, PUB]) Reset ¶
func (r *ClusterPublish[T, PUB]) Reset()
Reset implement define.Clear
type ClusterPublishServerUser ¶
type ClusterPublishServerUser[T, T1 any, US ServerUserSubjectPtr[T], PUB define.ProtoMessagePtr[T1]] struct { Pub T1 Us T define.DoNotCopy }
ClusterPublishServerUser publish msg to user topic designed to use objectpool, because Pub,Us will always escape to heap for more information, see ClusterClientServerUser.PublishUser create use NewPublishUser
func NewClusterPublishServerUser ¶
func NewClusterPublishServerUser[T, T1 any, US ServerUserSubjectPtr[T], PUB define.ProtoMessagePtr[T1]]() *ClusterPublishServerUser[T, T1, US, PUB]
NewClusterPublishServerUser create ClusterPublishServerUser use objectpool
func (*ClusterPublishServerUser[T, T1, US, PUB]) Free ¶
func (r *ClusterPublishServerUser[T, T1, US, PUB]) Free()
func (*ClusterPublishServerUser[T, T1, US, PUB]) Publish ¶
func (r *ClusterPublishServerUser[T, T1, US, PUB]) Publish(cnc *ClusterClientServerUser[T, US], c ctx.IContext) *berror.ErrMsg
Publish more info see ClusterClientServerUser.PublishUser
func (*ClusterPublishServerUser[T, T1, US, PUB]) Reset ¶
func (r *ClusterPublishServerUser[T, T1, US, PUB]) Reset()
Reset implement define.Clear
type ClusterRequest ¶
type ClusterRequest[T, T1 any, REQ define.ProtoMessagePtr[T], RESP define.ProtoMessagePtr[T1]] struct { Req T Resp T1 define.DoNotCopy }
ClusterRequest rpc with ClusterClient.
func NewClusterRequest ¶
func NewClusterRequest[T, T1 any, REQ define.ProtoMessagePtr[T], RESP define.ProtoMessagePtr[T1]]() *ClusterRequest[T, T1, REQ, RESP]
NewClusterRequest create a ClusterRequest use objectpool ClusterRequest just can only be used once
func (*ClusterRequest[T, T1, REQ, RESP]) Free ¶
func (r *ClusterRequest[T, T1, REQ, RESP]) Free()
func (*ClusterRequest[T, T1, REQ, RESP]) Request ¶
func (r *ClusterRequest[T, T1, REQ, RESP]) Request(cnc *ClusterClient, c ctx.IContext) *berror.ErrMsg
Request more info see ClusterClient.Request
func (*ClusterRequest[T, T1, REQ, RESP]) RequestToServer ¶
func (r *ClusterRequest[T, T1, REQ, RESP]) RequestToServer(cnc *ClusterClient, c ctx.IContext, toServerId int64) *berror.ErrMsg
RequestToServer more info see ClusterClient.RequestToServer
func (*ClusterRequest[T, T1, REQ, RESP]) Reset ¶
func (r *ClusterRequest[T, T1, REQ, RESP]) Reset()
Reset implement define.Clear
type ClusterRequestServerUser ¶
type ClusterRequestServerUser[T1, T2, T any, US ServerUserSubjectPtr[T], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2]] struct { Req T1 Resp T2 Us T define.DoNotCopy }
ClusterRequestServerUser rpc user topic designed to use objectpool, because Pub,Us will always escape to heap for more information, see ClusterClientServerUser.RequestUser create use NewPublishUser
func NewClusterRequestServerUser ¶
func NewClusterRequestServerUser[T1, T2, T any, US ServerUserSubjectPtr[T], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2]]() *ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]
NewClusterRequestServerUser create ClusterRequestServerUser use objectpool
func (*ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Free ¶
func (r *ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Free()
func (*ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Request ¶
func (r *ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Request( cnc *ClusterClientServerUser[T, US], c ctx.IContext, ) *berror.ErrMsg
Request more info see ClusterClientServerUser.RequestUser
func (*ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Reset ¶
func (r *ClusterRequestServerUser[T1, T2, T, US, REQ, RESP]) Reset()
Reset implement define.Clear
type NatsClient ¶
func NewNatsClient ¶
NewNatsClient one nats cluster client encapsulates the calling design of the entire framework param name Usually the server name ( baseenv.Config.ServerType ) param urls a nats cluster urls param timeout for request
func (*NatsClient) Conn ¶ added in v0.1.34
func (this_ *NatsClient) Conn() *nats.Conn
func (*NatsClient) Publish ¶
Publish msg to serverId is 0 or a cluster server node param pubMsg escapes to heap recommended use ClientPublish.Publish
func (*NatsClient) PublishRawData ¶
func (this_ *NatsClient) PublishRawData(c ctx.IContext, toServerId int64, msgName string, msgData []byte) *berror.ErrMsg
PublishRawData publish raw data to specified server instance of toServerId msgName is proto message name msgData is proto message data if toServerId == 0, PublishToServer == Publish
func (*NatsClient) PublishToServer ¶
func (this_ *NatsClient) PublishToServer(c ctx.IContext, toServerId int64, pubMsg proto.Message) *berror.ErrMsg
PublishToServer publish msg to specified server instance of toServerId if toServerId == 0, PublishToServer == Publish // recommended use ClientPublish.PublishToServer
func (*NatsClient) QueueSubscribe ¶
func (this_ *NatsClient) QueueSubscribe(subj string, h nats.MsgHandler) bool
QueueSubscribe queue subscribe
func (*NatsClient) QueueSubscribeWaitSuccess ¶
func (this_ *NatsClient) QueueSubscribeWaitSuccess(subj string, h nats.MsgHandler) bool
QueueSubscribeWaitSuccess QueueSubscribe and wait for success
func (*NatsClient) Request ¶
func (this_ *NatsClient) Request(c ctx.IContext, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
Request call rpc with serverId is 0 or a cluster server node respMsg is response message param reqMsg,respMsg escapes to heap recommended use ClientRequest.Request
func (*NatsClient) RequestRaw ¶
func (this_ *NatsClient) RequestRaw(c ctx.IContext, toServerId int64, reqMsgName string, reqMsgData []byte) ([]byte, *berror.ErrMsg)
RequestRaw send rpc to server if toServerId == 0, Receiver serverId is 0 or a cluster server node param reqMsgName is proto message name. param reqMsgData is proto message data. return nats.Msg.Ctx and berror.ErrMsg.
func (*NatsClient) RequestToServer ¶
func (this_ *NatsClient) RequestToServer(c ctx.IContext, toServerId int64, reqMsg proto.Message, respMsg proto.Message) *berror.ErrMsg
RequestToServer send rpc to specified server instance of toServerId if toServerId == 0, RequestToServer == Request req,resp : Will definitely escape to the heap because proto.MessageName and proto.Marshal and proto.Unmarshal
func (*NatsClient) Shutdown ¶
func (this_ *NatsClient) Shutdown()
Shutdown flush all subscriptions and close connection
func (*NatsClient) Subscribe ¶
func (this_ *NatsClient) Subscribe(subj string, h nats.MsgHandler) bool
Subscribe topic
func (*NatsClient) SubscribeWaitSuccess ¶
func (this_ *NatsClient) SubscribeWaitSuccess(subj string, h nats.MsgHandler) bool
SubscribeWaitSuccess Subscribe and wait for success
func (*NatsClient) Unsubscribe ¶
func (this_ *NatsClient) Unsubscribe(subj string)
Unsubscribe topic
type ServerIntUserSubject ¶
func (*ServerIntUserSubject) CreateSubj ¶
func (u *ServerIntUserSubject) CreateSubj(b *objectpool.Bytes)
func (*ServerIntUserSubject) CreateSubjSize ¶ added in v0.1.9
func (u *ServerIntUserSubject) CreateSubjSize() int
func (*ServerIntUserSubject) GetRoleID ¶ added in v0.1.39
func (u *ServerIntUserSubject) GetRoleID() int64
func (*ServerIntUserSubject) ParseSubj ¶ added in v0.1.9
func (u *ServerIntUserSubject) ParseSubj(s string) error
type ServerUserNatsClient ¶
type ServerUserNatsClient[T any, US ServerUserSubjectPtr[T]] struct { *NatsClient // contains filtered or unexported fields }
func NewServerUserNatsClient ¶
func NewServerUserNatsClient[T any, US ServerUserSubjectPtr[T]]( urls string, rpcTimeout time.Duration, userHandler nats.MsgHandler, opts ...UNOption, ) *ServerUserNatsClient[T, US]
func (*ServerUserNatsClient[T, US]) Close ¶ added in v0.1.3
func (nc *ServerUserNatsClient[T, US]) Close()
func (*ServerUserNatsClient[T, US]) PublishUser ¶
func (nc *ServerUserNatsClient[T, US]) PublishUser(c ctx.IContext, us US, pubMsg proto.Message) *berror.ErrMsg
PublishUser publish msg to user topic param us,pubMsg escapes to heap recommended use ClientPublishServerUser
func (*ServerUserNatsClient[T, US]) PublishUserMany ¶ added in v0.1.9
func (nc *ServerUserNatsClient[T, US]) PublishUserMany(c ctx.IContext, us US, pubMsg ...proto.Message) *berror.ErrMsg
PublishUserMany publish msg to user topic param us,pubMsg escapes to heap recommended use ClientPublishServerUser
func (*ServerUserNatsClient[T, US]) QueueSubscribeUser ¶
func (nc *ServerUserNatsClient[T, US]) QueueSubscribeUser(us US, handler nats.MsgHandler) bool
QueueSubscribeUser queue subscribe user topic param us not escapes to heap
func (*ServerUserNatsClient[T, US]) QueueSubscribeUserWaitSuccess ¶
func (nc *ServerUserNatsClient[T, US]) QueueSubscribeUserWaitSuccess(us US) bool
QueueSubscribeUserWaitSuccess QueueSubscribeUser and wait for success
func (*ServerUserNatsClient[T, US]) RequestUser ¶
func (nc *ServerUserNatsClient[T, US]) RequestUser(c ctx.IContext, us US, reqMsg proto.Message, out proto.Message) *berror.ErrMsg
RequestUser user topic rpc us,reqMsg,out escapes to heap recommended use ClientRequestServerUser
func (*ServerUserNatsClient[T, US]) SubscribeUser ¶
func (nc *ServerUserNatsClient[T, US]) SubscribeUser(us US) bool
SubscribeUser subscribe user topic param us not escapes to heap
func (*ServerUserNatsClient[T, US]) SubscribeUserWaitSuccess ¶
func (nc *ServerUserNatsClient[T, US]) SubscribeUserWaitSuccess(us US) bool
SubscribeUserWaitSuccess SubscribeUser and wait for success
func (*ServerUserNatsClient[T, US]) UnsubscribeUser ¶
func (nc *ServerUserNatsClient[T, US]) UnsubscribeUser(us US)
UnsubscribeUser unsubscribe user topic param us not escapes to heap
type ServerUserSubject ¶
type ServerUserSubject interface {
// GetRoleID returns the int64 role identifier used for NatsClient selection and dispatch routing.
// Must not return 0.
GetRoleID() int64
// CreateSubj create subj for NatsClient.SubscribeServerUser
// param b from objectpool.GetBytes
CreateSubj(*objectpool.Bytes)
// CreateSubjSize calculate size of CreateSubj
CreateSubjSize() int
// ParseSubj parse for subj
ParseSubj(s string) error
}
ServerUserSubject one user on one server type subscribe all message for this user deal by this subject example: subscribe "{ServerType}/{ServerId}/{RoleId}.>", publish "{serverType}/{serverId}/{roleId}.{MsgName}" because when NATS reconnects, it will send all the subjects subscribed to the current connection to NATS-Server for re-subscription. too many subjects will cause the reconnection to be too slow. so it is ideal for one user to subscribe to the same service once. Only int64 RoleID is supported by this framework.
type ServerUserSubjectPtr ¶
type ServerUserSubjectPtr[T any] interface { ServerUserSubject *T }
type UNOption ¶ added in v0.1.3
func NatsOptions ¶ added in v0.1.3
func UserQueueChanCount ¶ added in v0.1.3
UserQueueChanCount set the queue chan count, and per chan size is defaultQueueChanSize.