using System.Text; using Quartz; namespace OpenAuth.WebApi.boot; public class ConfigSubscribe : IJob { private MqttClientManager mqttClientManager; public void Subscribe() { // todo 订阅 "thing/product/{gateway_sn}/services_reply", string gatewaySn = "8UUXN5400A079H"; mqttClientManager.SubscribeAsync($"thing/product/{gatewaySn}/services_reply", async (args) => { // 确定主题 , 确定payload方法是 method var topic = args.ApplicationMessage.Topic; var payload = args.ApplicationMessage.Payload; var message = Encoding.UTF8.GetString(payload); }); } public async Task Execute(IJobExecutionContext context) { var serviceProvider = context.JobDetail.JobDataMap.Get("serviceProvider") as IServiceProvider; if (mqttClientManager != null) return; if (serviceProvider != null) { mqttClientManager = serviceProvider.GetService(typeof(MqttClientManager)) as MqttClientManager; Subscribe(); } return; } }