Documentation ¶
Index ¶
- type Bus
- type BusConf
- type BusType
- type CalleeHandler
- type EventBus
- type Handler
- type InProcRPC
- func (r *InProcRPC) Call(name string, args ...interface{}) (reflect.Value, error)
- func (r *InProcRPC) CallV2(name string, data []byte, timeout time.Duration) ([]byte, error)
- func (r *InProcRPC) Expose(name string, fn interface{})
- func (r *InProcRPC) ExposeV2(name string, handler CalleeHandler) error
- type InProcRPCBroker
- type Messager
- type MessagerConf
- type NatsBus
- type NatsRPC
- type RPC
- type RPCClient
- type RPCConf
- type RPCServer
- type RpcType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus interface { // Publish publishes data on the given topic. // This method is goroutine-safe. Publish(topic string, data []byte) error // Subscribe subscribes data on the given topic by registering a callback. // This method is goroutine-safe. Subscribe(topic string, fn Handler) error // SubscribeOnce calls Unsubscribe // This method is goroutine-safe. SubscribeOnce(topic string, fn Handler) error // Unsubscribe removes handler registered for a topic. // Returns error if there are no handlers subscribed to the topic. // This method is goroutine-safe. Unsubscribe(topic string, fn Handler) error }
Bus provides a message bus and expose API using pub/sub pattern.
func NewBus ¶
NewBus returns a new Bus endpoint and connects itself to the given broker. If conf is nil, bus endpoint will not be created.
func NewEventBus ¶
func NewNatsBus ¶
NewNatsBus creates a Bus endpoint according to the conf.
Returns nil and any error when failed.
type CalleeHandler ¶
CalleeHandler abstracts the RPC server side universal handler.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus - box for handlers and callbacks. based on https://github.com/asaskevich/EventBus/blob/master/event_bus.go
func (*EventBus) Publish ¶
Publish executes callback defined for a topic. Any additional argument will be transferred to the callback.
func (*EventBus) Subscribe ¶
Subscribe subscribes to a topic. Returns error if `fn` is not a function.
func (*EventBus) SubscribeOnce ¶
SubscribeOnce subscribes to a topic once. Handler will be removed after executing. Returns error if `fn` is not a function.
type InProcRPC ¶
type InProcRPC struct {
// contains filtered or unexported fields
}
InProcRPC implements RPC interface, including both server and client.
type InProcRPCBroker ¶
InProcRPCBroker holds handlers of rpc service.
type Messager ¶
Messager is a communication endpoint peer, which combines messaging patterns, namely Bus and RPC. It acts as an RPC server or client, a BUS subscriber or BUS publisher, or both.
func NewMessager ¶
func NewMessager(conf *MessagerConf) (*Messager, error)
NewMessager creates a messager using the given config.
NOTE: Bus endpoint will be created iff BusConf is not nil. RPC channel will be created iff RPCConf is not nil.
Returns nil when both conf are nil.
type MessagerConf ¶
type NatsBus ¶
type NatsBus struct { *nats.Conn // contains filtered or unexported fields }
NatsBus implements the Bus interface, thus can be used as a publisher, a subscriber or both. It creates a connection to a nats broker and use the connection object as the underlying carrier for bus messaging patterns.
type NatsRPC ¶
type NatsRPC struct { *nats.Conn // contains filtered or unexported fields }
NatsRPC implements the RPC interface, thus can be used as an RPCServer, an RPCClient or both. It creates a connection to a nats broker and use the connection object as the underlying carrier for RR messaging patterns.
func (*NatsRPC) CallV2 ¶
CallV2 calls a remote service identified by its name with the given args and expects response data or error, in the time limited by timeout.
type RPC ¶
RPC implements both sides of RPC service.
func NewInProcRPC ¶
func NewNatsRPC ¶
NewNatsRPC creates an RPC channel according to the conf.
Returns nil and any error when failed.
type RPCClient ¶
type RPCClient interface { //Call calls a remote method identified by its name with the given args. Call(name string, args ...interface{}) (reflect.Value, error) //CallV2 calls a remote service identified by its name with the given args //and expects response data or error, in the time limited by timeout. CallV2(name string, data []byte, timeout time.Duration) ([]byte, error) }
RPCClient defines caller side of an RPC service.
type RPCServer ¶
type RPCServer interface { //Expose register a method to rpc server by associating a function handler. Expose(name string, fn interface{}) //ExposeV2 register a method to rpc server by associating a handler. //Serialization based style. ExposeV2(name string, handler CalleeHandler) error }
RPCServer defines callee side of an RPC service.