[feat] Mqtt hook 调整
This commit is contained in:
		
							parent
							
								
									7d55b17630
								
							
						
					
					
						commit
						aa401d6048
					
				
							
								
								
									
										46
									
								
								mqtt.go
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								mqtt.go
									
									
									
									
									
								
							| @ -1,6 +1,8 @@ | |||||||
| package contracts | package contracts | ||||||
| 
 | 
 | ||||||
| import "github.com/samber/do" | import ( | ||||||
|  | 	"github.com/samber/do" | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| type MqttService interface { | type MqttService interface { | ||||||
| 	Start() error | 	Start() error | ||||||
| @ -8,13 +10,19 @@ type MqttService interface { | |||||||
| 	Restart() error | 	Restart() error | ||||||
| 
 | 
 | ||||||
| 	// 消息推送
 | 	// 消息推送
 | ||||||
| 	// @param topic 订阅的主题
 | 	//
 | ||||||
| 	// @param msg 传递的消息
 | 	// Example:
 | ||||||
| 	// @param retain 是否保留
 | 	//
 | ||||||
| 	// @param qos 传递的消息,
 | 	// Parameters:
 | ||||||
|  | 	//   topic 订阅的主题
 | ||||||
|  | 	//   msg 传递的消息
 | ||||||
|  | 	//   retain 是否保留
 | ||||||
|  | 	//   qos 传递的消息,
 | ||||||
| 	//      0: 至多一次, 如果发送失败,也就算了
 | 	//      0: 至多一次, 如果发送失败,也就算了
 | ||||||
| 	//      1: 至少一次, 消息将确保至少被传递一次,但可能会重复发送
 | 	//      1: 至少一次, 消息将确保至少被传递一次,但可能会重复发送
 | ||||||
| 	//      2: 确保只有一次, 确保消息仅被传递一次且没有重复传递
 | 	//      2: 确保只有一次, 确保消息仅被传递一次且没有重复传递
 | ||||||
|  | 	// Returns:
 | ||||||
|  | 	//   error - 执行结果
 | ||||||
| 	Publish(topic string, msg any, retain bool, qos byte) error | 	Publish(topic string, msg any, retain bool, qos byte) error | ||||||
| 
 | 
 | ||||||
| 	// 关闭消息队列
 | 	// 关闭消息队列
 | ||||||
| @ -32,15 +40,17 @@ type Mqtt interface { | |||||||
| 	// 取消订阅事件
 | 	// 取消订阅事件
 | ||||||
| 	OnUnsubscribed(g GlobalParams, topic string) error | 	OnUnsubscribed(g GlobalParams, topic string) error | ||||||
| 	// 消息发布事件
 | 	// 消息发布事件
 | ||||||
| 	OnMessage(g GlobalParams, topic string) error | 	OnMessage(g GlobalParams, topic string, retain bool, qos byte) error | ||||||
|  | 	// 消息被丢弃
 | ||||||
|  | 	OnMessageDropped(g GlobalParams, topic string, retain bool, qos byte) error | ||||||
| 	// 保留类型消息事件
 | 	// 保留类型消息事件
 | ||||||
| 	OnRetainMessage(g GlobalParams, topic string) error | 	// OnRetainMessage(g GlobalParams, topic string) error
 | ||||||
| 	// Qos消息完成事件
 | 	// Qos消息完成事件
 | ||||||
| 	OnQosMessage(g GlobalParams, topic string) error | 	// OnQosMessage(g GlobalParams, topic string) error
 | ||||||
| 	// 客户端超时事件
 | 	// 客户端超时事件
 | ||||||
| 	OnClientExpired(GlobalParams) error | 	// OnClientExpired(GlobalParams) error
 | ||||||
| 	// 保留消息超时事件
 | 	// 保留消息超时事件
 | ||||||
| 	OnRetainedExpired(g GlobalParams, topic string) error | 	// OnRetainedExpired(g GlobalParams, topic string) error
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type MqttHandle struct { | type MqttHandle struct { | ||||||
| @ -55,23 +65,11 @@ func (this MqttHandle) OnUnsubscribed(g GlobalParams, topic string) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (this MqttHandle) OnMessage(g GlobalParams, topic string) error { | func (this MqttHandle) OnMessage(g GlobalParams, topic string, retain bool, qos byte) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (this MqttHandle) OnRetainMessage(g GlobalParams, topic string) error { | func (this MqttHandle) OnMessageDropped(g GlobalParams, topic string, retain bool, qos byte) error { | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (this MqttHandle) OnQosMessage(g GlobalParams, topic string) error { |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (this MqttHandle) OnClientExpired(g GlobalParams) error { |  | ||||||
| 	return nil |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (this MqttHandle) OnRetainedExpired(g GlobalParams, topic string) error { |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user