messagex

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
const (
	Local    = iota // 本地通道
	RabbitMQ        // RabbitMQ 消息代理
)
View Source
const (
	MsgStartup = "messagex.startup"
)

Variables

This section is empty.

Functions

func HandleError

func HandleError(msg *Message, error *errors.Error)

func HandlePanic

func HandlePanic(msg *Message)

func Publish

func Publish(topic any, message *Message) (error *errors.Error)

func PublishNewMsg

func PublishNewMsg(ctx *gin.Context, topic any, content interface{}, groupId ...string)

func PublishWithCtx

func PublishWithCtx(ctx *gin.Context, topic any, message *Message) *errors.Error

func RegisterTopic

func RegisterTopic(topic any, handler func(message *Message) *errors.Error) (uint64, *errors.Error)

func ToMap

func ToMap(param interface{}) map[string]interface{}

ToMap converts a struct to a map[string]interface{} where the keys are the struct's field names and the values are the respective field values. Note: This function only works with structs and will return nil for non-struct parameters.

func UnSubscribe

func UnSubscribe(topic any, subID uint64) *errors.Error

Types

type BrokerType

type BrokerType int

BrokerType 定义了代理的类型。

type Message

type Message struct {
	ID      string
	GroupID string
	SubID   uint64
	Topic   string // 主题
	Content map[string]interface{}
}

Message 是消息的结构体。

func (*Message) DeepCopy

func (m *Message) DeepCopy() *Message

DeepCopy 创建Message的深拷贝

func (*Message) GetValue

func (m *Message) GetValue(key string) interface{}

func (*Message) GetValueFloat64

func (m *Message) GetValueFloat64(key string) float64

func (*Message) GetValueInt64

func (m *Message) GetValueInt64(key string) int64

func (*Message) GetValueStr

func (m *Message) GetValueStr(key string) string

func (*Message) LowerContentKey

func (m *Message) LowerContentKey()

func (*Message) SetValue

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

func (*Message) ToNewGinCtx

func (m *Message) ToNewGinCtx() *gin.Context

type MessageBroker

type MessageBroker interface {
	Subscribe(topic string, handler func(message *Message) *errors.Error) (uint64, *errors.Error)
	SubscribeGroup(topic string, groupID string, handler func(message *Message) *errors.Error) (uint64, *errors.Error) // 指定groupID
	UnSubscribe(topic string, subID uint64) *errors.Error
	Publish(topic string, message *Message) *errors.Error
	PublishGroup(topic string, groupID string, message *Message) *errors.Error // 指定groupID
	TopicList() []string
}

MessageBroker 定义了消息代理的行为。

type MessageService

type MessageService struct {
	BrokerType BrokerType
	Broker     MessageBroker
}
var GService MessageService

func Get

func Get(brokerType BrokerType) *MessageService

func GetDef

func GetDef() *MessageService

func GetInstance

func GetInstance(brokerType BrokerType) *MessageService

type MessageType

type MessageType string

MessageType 定义了消息的内容。

type SimpleMessageBroker

type SimpleMessageBroker struct {
	// contains filtered or unexported fields
}

func NewSimple

func NewSimple() *SimpleMessageBroker

func (*SimpleMessageBroker) Publish

func (mb *SimpleMessageBroker) Publish(topic string, message *Message) *errors.Error

func (*SimpleMessageBroker) PublishGroup

func (mb *SimpleMessageBroker) PublishGroup(topic string, groupID string, message *Message) *errors.Error

func (*SimpleMessageBroker) StartListening

func (mb *SimpleMessageBroker) StartListening()

func (*SimpleMessageBroker) Startup

func (mb *SimpleMessageBroker) Startup(topic string) *errors.Error

func (*SimpleMessageBroker) StopListening

func (mb *SimpleMessageBroker) StopListening()

func (*SimpleMessageBroker) Subscribe

func (mb *SimpleMessageBroker) Subscribe(topic string, handler func(message *Message) *errors.Error) (uint64, *errors.Error)

func (*SimpleMessageBroker) SubscribeGroup

func (mb *SimpleMessageBroker) SubscribeGroup(topic string, groupID string, handler func(message *Message) *errors.Error) (uint64, *errors.Error)

func (*SimpleMessageBroker) TopicList

func (mb *SimpleMessageBroker) TopicList() []string

func (*SimpleMessageBroker) UnSubscribe

func (mb *SimpleMessageBroker) UnSubscribe(topic string, subID uint64) *errors.Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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