[feat] mqtt 支持
This commit is contained in:
		
							parent
							
								
									0e21627c9a
								
							
						
					
					
						commit
						7d55b17630
					
				
							
								
								
									
										40
									
								
								mqtt.go
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								mqtt.go
									
									
									
									
									
								
							@ -2,7 +2,7 @@ package contracts
 | 
			
		||||
 | 
			
		||||
import "github.com/samber/do"
 | 
			
		||||
 | 
			
		||||
type Mqtt interface {
 | 
			
		||||
type MqttService interface {
 | 
			
		||||
	Start() error
 | 
			
		||||
	Stop() error
 | 
			
		||||
	Restart() error
 | 
			
		||||
@ -21,58 +21,62 @@ type Mqtt interface {
 | 
			
		||||
	Close(origin string)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MqttController interface {
 | 
			
		||||
type Mqtt interface {
 | 
			
		||||
	Controller
 | 
			
		||||
	// 链接
 | 
			
		||||
	// OnConnect(g GlobalParams, topic string) error
 | 
			
		||||
	// 断开链接
 | 
			
		||||
	// OnDisconnect(g GlobalParams, topic string) error
 | 
			
		||||
	// 订阅事件
 | 
			
		||||
	OnSubscribed(GlobalParams) error
 | 
			
		||||
	OnSubscribed(g GlobalParams, topic string) error
 | 
			
		||||
	// 取消订阅事件
 | 
			
		||||
	OnUnsubscribed(GlobalParams) error
 | 
			
		||||
	OnUnsubscribed(g GlobalParams, topic string) error
 | 
			
		||||
	// 消息发布事件
 | 
			
		||||
	OnMessage(GlobalParams) error
 | 
			
		||||
	OnMessage(g GlobalParams, topic string) error
 | 
			
		||||
	// 保留类型消息事件
 | 
			
		||||
	OnRetainMessage(GlobalParams) error
 | 
			
		||||
	OnRetainMessage(g GlobalParams, topic string) error
 | 
			
		||||
	// Qos消息完成事件
 | 
			
		||||
	OnQosMessage(GlobalParams) error
 | 
			
		||||
	OnQosMessage(g GlobalParams, topic string) error
 | 
			
		||||
	// 客户端超时事件
 | 
			
		||||
	OnClientExpired(GlobalParams) error
 | 
			
		||||
	// 保留消息超时事件
 | 
			
		||||
	OnRetainedExpired(GlobalParams) error
 | 
			
		||||
	OnRetainedExpired(g GlobalParams, topic string) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MqttHandleController struct {
 | 
			
		||||
type MqttHandle struct {
 | 
			
		||||
	Controller
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnSubscribed(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnSubscribed(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnUnsubscribed(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnUnsubscribed(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnMessage(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnMessage(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnRetainMessage(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnRetainMessage(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnQosMessage(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnQosMessage(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnClientExpired(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnClientExpired(g GlobalParams) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this MqttHandleController) OnRetainedExpired(g GlobalParams) error {
 | 
			
		||||
func (this MqttHandle) OnRetainedExpired(g GlobalParams, topic string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewMqttController(container *do.Injector) MqttController {
 | 
			
		||||
	return &MqttHandleController{
 | 
			
		||||
func NewMqttController(container *do.Injector) Mqtt {
 | 
			
		||||
	return &MqttHandle{
 | 
			
		||||
		Controller: &BaseController{container},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,9 +7,11 @@ type Service interface {
 | 
			
		||||
	RegGRpcs(items map[string]GRpc) error
 | 
			
		||||
	RegJobs(items map[string]Job) error
 | 
			
		||||
	RegCrons(items map[string]Cron) error
 | 
			
		||||
	RegMqtts(items map[string]Mqtt) error
 | 
			
		||||
	GetResListener(code string) (ResListener, bool)
 | 
			
		||||
	GetAppController(code string) (Controller, bool)
 | 
			
		||||
	GetAppGRpc(code string) (GRpc, bool)
 | 
			
		||||
	GetAppJob(code string) (Job, bool)
 | 
			
		||||
	GetAppCron(code string) (Cron, bool)
 | 
			
		||||
	GetAppMqtt(code string) (Mqtt, bool)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user