message

package
v0.0.0-...-765e33d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMsgExpireTime              = 24 * time.Hour
	DefaultRetryIntervalForGetWaiting = 2 * time.Second

	EnvRedisAddr     = "REDIS_ADDR"
	EnvRedisDB       = "REDIS_DB"
	EnvRedisPassword = "REDIS_PASS"
)

Variables

View Source
var (
	ErrSetGlobal     = &Error{Code: "ErrSetGlobal", Message: "Error setting global message"}
	ErrPublish       = &Error{Code: "ErrPublish", Message: "Error publishing a message"}
	ErrSetIP         = &Error{Code: "ErrSetIP", Message: "Error setting IP"}
	ErrGetIP         = &Error{Code: "ErrGetIP", Message: "Error getting IP"}
	ErrMsgNotFound   = &Error{Code: "ErrMsgNotFound", Message: "Message not found"}
	ErrGetPubResult  = &Error{Code: "ErrGetPubResult", Message: "Error getting publish result"}
	ErrNoSubscribers = &Error{Code: "ErrNoSubscribers", Message: "No subscribers"}
	ErrTypeCasting   = &Error{Code: "ErrTypeCasting", Message: "Type casting failed"}
	ErrCtxDone       = &Error{Code: "ErrCtxDone", Message: "Context Done"}
)

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    string
	Message string
	Err     error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Wrap

func (e *Error) Wrap(err error) error

type Message

type Message struct {
	Client  *redis.Client
	NodeUID string // the UID is used to identify the node and to receive messages
}

func (*Message) Get

func (m *Message) Get(redisKey string) (interface{}, error)

Get gets the value of the given key from Redis.

func (*Message) GetIP

func (m *Message) GetIP(nodeUID string) (string, error)

GetIP gets the IP address of a node with the given UID.

func (*Message) GetIPWaiting

func (m *Message) GetIPWaiting(ctx context.Context, nodeUID string) (string, error)

GetIPWaiting gets the IP address of a node with the given UID. It waits until either the IP address is set by the node or the context is done.

func (*Message) GetWaiting

func (m *Message) GetWaiting(ctx context.Context, redisKey string) (interface{}, error)

GetWaiting gets the value of the given key from Redis. It waits until the value is set by someone or the context is done.

func (*Message) OnReceive

func (m *Message) OnReceive(key string, handler func(value interface{}))

OnReceive sets a handler to receive messages from the given key. The handler will be called when a message is received from the given key.

func (*Message) OnReceiveGlobal

func (m *Message) OnReceiveGlobal(key string, handler func(value interface{}))

OnReceiveGlobal sets a handler to receive messages from the given key. The handler will be called when a message is received from the given key.

func (*Message) Receive

func (m *Message) Receive(key string) (interface{}, error)

Receive receives a message from the given key. It waits until a message is received from the given key.

func (*Message) ReceiveGlobal

func (m *Message) ReceiveGlobal(key string) (interface{}, error)

ReceiveGlobal receives a message from the given key. It waits until a message is received from the given key.

func (*Message) Send

func (m *Message) Send(receiverUID, key string, value interface{}) error

Send sends a message to the receiver with the given UID. Please note that the other node must be listening to the same key to receive the message.

func (*Message) SendGlobal

func (m *Message) SendGlobal(key string, value interface{}) error

SendGlobal sends a message to all nodes with the given key. Please note that the other nodes must be listening to the same key to receive the message.

func (*Message) Set

func (m *Message) Set(redisKey string, value interface{}) error

Set sets the value of the given key in Redis.

func (*Message) SetIP

func (m *Message) SetIP(ipAddr string) error

SetIP sets the IP address of the node that is calling it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL