You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
}
}