func ParseJsonConfig(jsonBytes []byte) (map[string]interface{}, error)
Helper function for parsing a JSON configuration for the message bus from the given byte blob.
Note: This method automatically takes care of using a JSON decode having set the UseNumber() flag.
func ReadJsonConfig(fileName string) (map[string]interface{}, error)
Helper function for reading a JSON configuration for the message bus from a JSON configuration file.
Note: This method automatically takes care of using a JSON decode having set the UseNumber() flag.
Message bus client object
type MsgbusClient struct {
// contains filtered or unexported fields
}
func NewMsgbusClient(config map[string]interface{}) (*MsgbusClient, error)
Initialize a new message bus context.
func (ctx *MsgbusClient) Close()
Close the messaage bus client.
**IMPORTANT NOTE:** After this is called, no other operations using this context will succeed (including methods on publishers, subscribers, etc.).
func (ctx *MsgbusClient) GetService(serviceName string) (*ServiceRequester, error)
func (ctx *MsgbusClient) IsClosed() bool
Check if the message bus client has already been destroyed.
func (ctx *MsgbusClient) NewPublisher(topic string) (*Publisher, error)
Create a new publisher on the message bus context.
func (ctx *MsgbusClient) NewService(serviceName string) (*Service, error)
Create a new service to receive requests over and send responses from.
func (ctx *MsgbusClient) NewSubscriber(topic string) (*Subscriber, error)
Create a new subscriber for the specified topic.
type Publisher struct {
// contains filtered or unexported fields
}
func (pub *Publisher) Close() error
func (pub *Publisher) Publish(msg interface{}) error
Service object. This object is not thread-safe.
Since service objects are not safe, all requests and sending of responses must occur in the same thread (i.e. goroutine).
type Service struct {
// contains filtered or unexported fields
}
func (service *Service) Close()
Close the subscriber
func (service *Service) ReceiveRequest(timeout int) (*types.MsgEnvelope, error)
Receive a request issued to the service.
The timeout parameter determines how the receive call will function. If the timeout is less than 0, then it will block for ever. If it is set 0, then it will return immediately. If the caller wishes there to be a timeout, then the timeout should be specified in milliseconds.
For the no wait and timeout modes, if no message is received then both return values will be nil.
func (service *Service) Response(response interface{}) error
Send a response to a request received by the service.
ServiceRequester object. This object is not thread-safe.
Since service request objects are not safe, all sending of requests and receiving of responses must occur in the same thread (i.e. goroutine).
type ServiceRequester struct {
// contains filtered or unexported fields
}
func (service *ServiceRequester) Close()
Close the subscriber
func (service *ServiceRequester) ReceiveResponse(timeout int) (*types.MsgEnvelope, error)
Receive a response to a previously sent request.
The timeout parameter determines how the receive call will function. If the timeout is less than 0, then it will block for ever. If it is set 0, then it will return immediately. If the caller wishes there to be a timeout, then the timeout should be specified in milliseconds.
For the no wait and timeout modes, if no message is received then both return values will be nil.
func (service *ServiceRequester) Request(request interface{}) error
Send a request to the service.
Subscriber object. This object is not thread-safe.
type Subscriber struct { MessageChannel chan *types.MsgEnvelope ErrorChannel chan error // contains filtered or unexported fields }
func (subscriber *Subscriber) Close()
Close the subscriber