Documentation
¶
Index ¶
- type CommunicationFactory
- type DefaultCommunicationFactory
- type DefaultEventBus
- func (b *DefaultEventBus) Close() error
- func (b *DefaultEventBus) Publish(event Event) error
- func (b *DefaultEventBus) Subscribe(eventType EventType, handler EventHandler) (string, error)
- func (b *DefaultEventBus) SubscribeWithFilter(eventType EventType, handler EventHandler, filter EventFilter) (string, error)
- func (b *DefaultEventBus) SubscribeWithOptions(options SubscriptionOptions) (string, error)
- func (b *DefaultEventBus) Unsubscribe(subscriptionID string) error
- type Event
- type EventBus
- type EventFilter
- type EventHandler
- type EventPriority
- type EventSubscription
- type EventType
- type GRPCCommunication
- func (c *GRPCCommunication) Close() error
- func (c *GRPCCommunication) GetService(name string) (interface{}, error)
- func (c *GRPCCommunication) Publish(topic string, message interface{}) error
- func (c *GRPCCommunication) ReceiveMessage() (string, interface{}, error)
- func (c *GRPCCommunication) RegisterService(service interface{}) error
- func (c *GRPCCommunication) SendMessage(target string, message interface{}) error
- func (c *GRPCCommunication) Subscribe(topic string, handler func(message interface{})) error
- type GRPCOptions
- type HTTPCommunication
- func (c *HTTPCommunication) Close() error
- func (c *HTTPCommunication) GetService(name string) (interface{}, error)
- func (c *HTTPCommunication) Publish(topic string, message interface{}) error
- func (c *HTTPCommunication) ReceiveMessage() (string, interface{}, error)
- func (c *HTTPCommunication) RegisterService(service interface{}) error
- func (c *HTTPCommunication) SendMessage(target string, message interface{}) error
- func (c *HTTPCommunication) Subscribe(topic string, handler func(message interface{})) error
- type HTTPOptions
- type InProcessCommunication
- func (c *InProcessCommunication) Close() error
- func (c *InProcessCommunication) GetService(name string) (interface{}, error)
- func (c *InProcessCommunication) Publish(topic string, message interface{}) error
- func (c *InProcessCommunication) ReceiveMessage() (string, interface{}, error)
- func (c *InProcessCommunication) RegisterService(service interface{}) error
- func (c *InProcessCommunication) SendMessage(target string, message interface{}) error
- func (c *InProcessCommunication) Subscribe(topic string, handler func(message interface{})) error
- type Message
- type SubscriptionOptions
- type WebSocketCommunication
- func (c *WebSocketCommunication) Close() error
- func (c *WebSocketCommunication) GetService(name string) (interface{}, error)
- func (c *WebSocketCommunication) Publish(topic string, message interface{}) error
- func (c *WebSocketCommunication) ReceiveMessage() (string, interface{}, error)
- func (c *WebSocketCommunication) RegisterService(service interface{}) error
- func (c *WebSocketCommunication) SendMessage(target string, message interface{}) error
- func (c *WebSocketCommunication) Subscribe(topic string, handler func(message interface{})) error
- type WebSocketOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommunicationFactory ¶
type CommunicationFactory interface {
// CreateCommunication 创建通信实例
// protocol: 通信协议
// options: 选项
// 返回: 通信实例和错误
CreateCommunication(protocol sdk.CommunicationProtocol, options map[string]interface{}) (sdk.Communication, error)
// RegisterHandler 注册协议处理器
// protocol: 通信协议
// handler: 处理器
RegisterHandler(protocol sdk.CommunicationProtocol, handler sdk.CommunicationHandler)
}
CommunicationFactory 通信工厂 用于创建不同类型的通信实例
type DefaultCommunicationFactory ¶
type DefaultCommunicationFactory struct {
// contains filtered or unexported fields
}
DefaultCommunicationFactory 默认通信工厂实现
func NewCommunicationFactory ¶
func NewCommunicationFactory(logger hclog.Logger) *DefaultCommunicationFactory
NewCommunicationFactory 创建一个新的通信工厂
func (*DefaultCommunicationFactory) CreateCommunication ¶
func (f *DefaultCommunicationFactory) CreateCommunication(protocol sdk.CommunicationProtocol, options map[string]interface{}) (sdk.Communication, error)
CreateCommunication 创建通信实例
func (*DefaultCommunicationFactory) RegisterHandler ¶
func (f *DefaultCommunicationFactory) RegisterHandler(protocol sdk.CommunicationProtocol, handler sdk.CommunicationHandler)
RegisterHandler 注册协议处理器
type DefaultEventBus ¶
type DefaultEventBus struct {
// contains filtered or unexported fields
}
DefaultEventBus 默认事件总线实现
func (*DefaultEventBus) Subscribe ¶
func (b *DefaultEventBus) Subscribe(eventType EventType, handler EventHandler) (string, error)
Subscribe 订阅事件
func (*DefaultEventBus) SubscribeWithFilter ¶
func (b *DefaultEventBus) SubscribeWithFilter(eventType EventType, handler EventHandler, filter EventFilter) (string, error)
SubscribeWithFilter 带过滤器订阅事件
func (*DefaultEventBus) SubscribeWithOptions ¶
func (b *DefaultEventBus) SubscribeWithOptions(options SubscriptionOptions) (string, error)
SubscribeWithOptions 带选项订阅事件
func (*DefaultEventBus) Unsubscribe ¶
func (b *DefaultEventBus) Unsubscribe(subscriptionID string) error
Unsubscribe 取消订阅
type Event ¶
type Event struct {
// 事件类型
Type EventType
// 事件源
Source string
// 事件ID
ID string
// 事件优先级
Priority EventPriority
// 事件时间
Timestamp time.Time
// 事件数据
Data map[string]interface{}
}
Event 事件
type EventBus ¶
type EventBus interface {
// Publish 发布事件
// event: 事件
// 返回: 错误
Publish(event Event) error
// Subscribe 订阅事件
// eventType: 事件类型
// handler: 事件处理器
// 返回: 订阅ID和错误
Subscribe(eventType EventType, handler EventHandler) (string, error)
// SubscribeWithFilter 带过滤器订阅事件
// eventType: 事件类型
// handler: 事件处理器
// filter: 事件过滤器
// 返回: 订阅ID和错误
SubscribeWithFilter(eventType EventType, handler EventHandler, filter EventFilter) (string, error)
// SubscribeWithOptions 带选项订阅事件
// options: 订阅选项
// 返回: 订阅ID和错误
SubscribeWithOptions(options SubscriptionOptions) (string, error)
// Unsubscribe 取消订阅
// subscriptionID: 订阅ID
// 返回: 错误
Unsubscribe(subscriptionID string) error
// Close 关闭事件总线
// 返回: 错误
Close() error
}
EventBus 事件总线 提供事件发布和订阅功能
type EventPriority ¶
type EventPriority int
EventPriority 事件优先级
const ( // PriorityLow 低优先级 PriorityLow EventPriority = iota // PriorityNormal 普通优先级 PriorityNormal // PriorityHigh 高优先级 PriorityHigh // PriorityCritical 关键优先级 PriorityCritical )
type EventSubscription ¶
type EventSubscription struct {
// 订阅ID
ID string
// 事件类型
Type EventType
// 事件源
Source string
// 事件处理器
Handler EventHandler
// 事件过滤器
Filter EventFilter
// 是否同步处理
Synchronous bool
// 订阅时间
SubscribedAt time.Time
}
EventSubscription 事件订阅
type GRPCCommunication ¶
type GRPCCommunication struct {
// contains filtered or unexported fields
}
GRPCCommunication gRPC通信实现
func NewGRPCCommunication ¶
func NewGRPCCommunication(options GRPCOptions) (*GRPCCommunication, error)
NewGRPCCommunication 创建一个新的gRPC通信
func (*GRPCCommunication) GetService ¶
func (c *GRPCCommunication) GetService(name string) (interface{}, error)
GetService 获取服务
func (*GRPCCommunication) Publish ¶
func (c *GRPCCommunication) Publish(topic string, message interface{}) error
Publish 发布消息到主题
func (*GRPCCommunication) ReceiveMessage ¶
func (c *GRPCCommunication) ReceiveMessage() (string, interface{}, error)
ReceiveMessage 接收消息
func (*GRPCCommunication) RegisterService ¶
func (c *GRPCCommunication) RegisterService(service interface{}) error
RegisterService 注册服务
func (*GRPCCommunication) SendMessage ¶
func (c *GRPCCommunication) SendMessage(target string, message interface{}) error
SendMessage 发送消息
func (*GRPCCommunication) Subscribe ¶
func (c *GRPCCommunication) Subscribe(topic string, handler func(message interface{})) error
Subscribe 订阅主题
type GRPCOptions ¶
type GRPCOptions struct {
// 地址
Address string
// 是否为服务器
IsServer bool
// 日志记录器
Logger hclog.Logger
// 事件总线
EventBus EventBus
// 服务注册函数
ServiceRegistrar func(*grpc.Server)
// 客户端连接选项
DialOptions []grpc.DialOption
// 服务器选项
ServerOptions []grpc.ServerOption
// 超时时间
Timeout time.Duration
}
GRPCOptions gRPC选项
type HTTPCommunication ¶
type HTTPCommunication struct {
// contains filtered or unexported fields
}
HTTPCommunication HTTP通信实现
func NewHTTPCommunication ¶
func NewHTTPCommunication(options HTTPOptions) (*HTTPCommunication, error)
NewHTTPCommunication 创建一个新的HTTP通信
func (*HTTPCommunication) GetService ¶
func (c *HTTPCommunication) GetService(name string) (interface{}, error)
GetService 获取服务
func (*HTTPCommunication) Publish ¶
func (c *HTTPCommunication) Publish(topic string, message interface{}) error
Publish 发布消息到主题
func (*HTTPCommunication) ReceiveMessage ¶
func (c *HTTPCommunication) ReceiveMessage() (string, interface{}, error)
ReceiveMessage 接收消息
func (*HTTPCommunication) RegisterService ¶
func (c *HTTPCommunication) RegisterService(service interface{}) error
RegisterService 注册服务
func (*HTTPCommunication) SendMessage ¶
func (c *HTTPCommunication) SendMessage(target string, message interface{}) error
SendMessage 发送消息
func (*HTTPCommunication) Subscribe ¶
func (c *HTTPCommunication) Subscribe(topic string, handler func(message interface{})) error
Subscribe 订阅主题
type HTTPOptions ¶
type HTTPOptions struct {
// 地址
Address string
// 是否为服务器
IsServer bool
// 日志记录器
Logger hclog.Logger
// 事件总线
EventBus EventBus
// 路由注册函数
RouteRegistrar func(*mux.Router)
// 客户端选项
ClientOptions *http.Client
// 服务器选项
ServerOptions *http.Server
// 超时时间
Timeout time.Duration
}
HTTPOptions HTTP选项
type InProcessCommunication ¶
type InProcessCommunication struct {
// contains filtered or unexported fields
}
InProcessCommunication 进程内通信实现
func (*InProcessCommunication) GetService ¶
func (c *InProcessCommunication) GetService(name string) (interface{}, error)
GetService 获取服务
func (*InProcessCommunication) Publish ¶
func (c *InProcessCommunication) Publish(topic string, message interface{}) error
Publish 发布消息到主题
func (*InProcessCommunication) ReceiveMessage ¶
func (c *InProcessCommunication) ReceiveMessage() (string, interface{}, error)
ReceiveMessage 接收消息
func (*InProcessCommunication) RegisterService ¶
func (c *InProcessCommunication) RegisterService(service interface{}) error
RegisterService 注册服务
func (*InProcessCommunication) SendMessage ¶
func (c *InProcessCommunication) SendMessage(target string, message interface{}) error
SendMessage 发送消息
func (*InProcessCommunication) Subscribe ¶
func (c *InProcessCommunication) Subscribe(topic string, handler func(message interface{})) error
Subscribe 订阅主题
type Message ¶
type Message struct {
// 消息类型
Type string `json:"type"`
// 消息目标
Target string `json:"target"`
// 消息源
Source string `json:"source"`
// 消息ID
ID string `json:"id"`
// 消息时间
Timestamp time.Time `json:"timestamp"`
// 消息数据
Data map[string]interface{} `json:"data"`
}
Message WebSocket消息
type SubscriptionOptions ¶
type SubscriptionOptions struct {
// 事件类型
Type EventType
// 事件源
Source string
// 事件处理器
Handler EventHandler
// 事件过滤器
Filter EventFilter
// 是否同步处理
Synchronous bool
// 订阅ID
ID string
}
SubscriptionOptions 订阅选项
type WebSocketCommunication ¶
type WebSocketCommunication struct {
// contains filtered or unexported fields
}
WebSocketCommunication WebSocket通信实现
func NewWebSocketCommunication ¶
func NewWebSocketCommunication(options WebSocketOptions) (*WebSocketCommunication, error)
NewWebSocketCommunication 创建一个新的WebSocket通信
func (*WebSocketCommunication) GetService ¶
func (c *WebSocketCommunication) GetService(name string) (interface{}, error)
GetService 获取服务
func (*WebSocketCommunication) Publish ¶
func (c *WebSocketCommunication) Publish(topic string, message interface{}) error
Publish 发布消息到主题
func (*WebSocketCommunication) ReceiveMessage ¶
func (c *WebSocketCommunication) ReceiveMessage() (string, interface{}, error)
ReceiveMessage 接收消息
func (*WebSocketCommunication) RegisterService ¶
func (c *WebSocketCommunication) RegisterService(service interface{}) error
RegisterService 注册服务
func (*WebSocketCommunication) SendMessage ¶
func (c *WebSocketCommunication) SendMessage(target string, message interface{}) error
SendMessage 发送消息
func (*WebSocketCommunication) Subscribe ¶
func (c *WebSocketCommunication) Subscribe(topic string, handler func(message interface{})) error
Subscribe 订阅主题
type WebSocketOptions ¶
type WebSocketOptions struct {
// 地址
Address string
// 是否为服务器
IsServer bool
// 日志记录器
Logger hclog.Logger
// 事件总线
EventBus EventBus
// 路由注册函数
RouteRegistrar func(*mux.Router)
// 服务器选项
ServerOptions *http.Server
// 超时时间
Timeout time.Duration
// 心跳间隔
HeartbeatInterval time.Duration
}
WebSocketOptions WebSocket选项