Documentation
¶
Index ¶
- Variables
- func Broadcast(topic string, message []byte, options ...*Option) (err error)
- func DirectBroadcast(nodeId string, topic string, message []byte, options ...*Option) error
- func Dispatch(topic string, message []byte)
- func LocalBroadcast(topic string, message []byte)
- func Self() string
- func SetAdapters(adapters []AdapterConfig)
- func SetGlobalOptions(options ...*Option)
- func Subscribe(topicPattern string, dispatcher Dispatcher)
- func Unsubscribe(topicPattern string, dispatcher Dispatcher)
- type Adapter
- type AdapterConfig
- type Dispatcher
- type DispatcherFuncImpl
- type DummyAdapter
- type MessageType
- type Option
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoAdapter = errors.New("no adapter matches topic to broadcast the message")
)
Functions ¶
func DirectBroadcast ¶
DirectBroadcast Broadcasts ServiceMsg on given topic to a given node.
func Dispatch ¶
Dispatch used by adapters, process and delivery messages coming from backend (redis, kafka, *MQ), decrypting and decompressing if necessary.
func LocalBroadcast ¶
LocalBroadcast broadcasts message on given topic only for the current node.
`topic` - The topic to broadcast to, ie: `"users:123"` `message` - The payload of the broadcast
func SetAdapters ¶
func SetAdapters(adapters []AdapterConfig)
SetAdapters configure the adapters topics.
Allows the application to have instances specialized by topics.
## Example
SetAdapters([]AdapterConfig{
{&RedisAdapter{Addr: "admin.redis-host:6379"}, []string{"admin:*"}},
{&RedisAdapter{Addr: "global.redis-host:6379"}, []string{"*"}},
})
func SetGlobalOptions ¶
func SetGlobalOptions(options ...*Option)
SetGlobalOptions set global options for sending messages
func Subscribe ¶
func Subscribe(topicPattern string, dispatcher Dispatcher)
func Unsubscribe ¶
func Unsubscribe(topicPattern string, dispatcher Dispatcher)
Unsubscribe the dispatchFunc from the pubsub adapter's topic.
Types ¶
type Adapter ¶
type Adapter interface {
// Name the Adapter name
Name() string
// Subscribe the Adapter that has an external broker must subscribe to the given topic
Subscribe(topic string)
// Unsubscribe the Adapter that has an external broker must unsubscribe to the given topic
Unsubscribe(topic string)
// Broadcast the given topic and message to all nodes in the cluster (except the current node itself).
Broadcast(topic string, message []byte, opts map[string]any) error
}
Adapter Specification to implement a custom PubSub adapter.
type AdapterConfig ¶
type AdapterConfig struct {
// Adapter The adapter instance being configured
Adapter Adapter
// Keyring allow to define a custom Keyring use for message encryption
Keyring *crypto.Keyring
// Options options that will be passed to the adapter during the broadcast
Options []Option
// Topics The topic name pattern this adapter must match
Topics []string
// RawMessage when true, do not encode messages when transmitting to adapter
RawMessage bool
// EnableEncryption enable/disable message encryption
DisableEncryption bool
// DisableCompression is used to control message compression. This can be used to reduce bandwidth usage at
// the cost of slightly more CPU utilization.
DisableCompression bool
}
func GetAdapter ¶
func GetAdapter(topic string) *AdapterConfig
GetAdapter Gets the adapter associated with a topic.
type Dispatcher ¶
func DispatcherFunc ¶
func DispatcherFunc(d func(topic string, message []byte, from string)) Dispatcher
type DispatcherFuncImpl ¶
type DummyAdapter ¶
type DummyAdapter struct {
}
DummyAdapter default adapter for local message distribution (only for the current node)
func (*DummyAdapter) Name ¶
func (a *DummyAdapter) Name() string
func (*DummyAdapter) Subscribe ¶
func (a *DummyAdapter) Subscribe(topic string)
func (*DummyAdapter) Unsubscribe ¶
func (a *DummyAdapter) Unsubscribe(topic string)
type MessageType ¶ added in v1.0.7
type MessageType uint8
MessageType is an integer ID of a type of message that can be received on network channels from other members.
const ( MessageTypeCompress MessageType = iota MessageTypeEncrypt MessageTypeBroadcast MessageTypeDirectBroadcast IndirectPingMsg AckRespMsg SuspectMsg AliveMsg DeadMsg PushPullMsg CompoundMsg UserMsg NackRespMsg ErrMsg )
The list of available message types.