我已经设置了一个WebJob,该网络被每分钟发送到通知Hub的WebJob,以进行测试目的,我需要它发送多个通知而不是仅发送通知。
我试图仅发送一系列通知对象而不是一个对象,但这似乎不起作用。
function.cs
public class Functions
{
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void SendNotif1([TimerTrigger("0 * * * * *")] TimerInfo time, TextWriter log, [NotificationHub] out Notification notification)
{
string title = "Hello";
string message = "Message";
notification = new GcmNotification(ToGcmPayload(title, message));
}
private static string ToGcmPayload(string title, string message)
{
var gcmPayloadModel = new
{
data = new
{
FormType = "Next scheduler",
MemberForm = "Hello"
}
};
return JsonConvert.SerializeObject(gcmPayloadModel);
}
}
我是否想以错误的方式这样做?
不确定您是否打算发送该代码段,但我找到了原始源。
// This binding sends multiple push notification to any clients registered with the template
// when method successfully exits.
public static void SendNotificationsOnTimerTrigger(
[TimerTrigger("*/30 * * * * *")] TimerInfo timerInfo,
[NotificationHub] out Notification[] notifications)
{
notifications = new TemplateNotification[]
{
GetTemplateNotification("Message1"),
GetTemplateNotification("Message2")
};
}
private static IDictionary<string, string> GetTemplateProperties(string message)
{
Dictionary<string, string> templateProperties = new Dictionary<string, string>();
templateProperties["message"] = message;
return templateProperties;
}
请参阅https://github.com/azure/azure-webjobs-sdk-extensions/blob/migrate_notification_hubs/src/extensionssampamplame/samplemp/notificationhubsamples.cs
我没有评论的代表,但我相信,根据此问题,上述解决方案仅适用于版本1类型功能,而不是版本2