我已经设置了一个WebJob,该WebJob每分钟都会向NotificationHub发送一个通知以进行测试,我需要它发送多个通知而不只是一个通知。
我试图只发送一个Notification对象数组,而不只是发送一个对象,但这似乎不起作用。
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);
}
}
我是想用错误的方式吗?
答案 0 :(得分:0)
不确定是否要发送该代码段,但我找到了原始源。
// 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;
}
答案 1 :(得分:0)
我没有发表评论的代表,但我相信根据this 问题,上述解决方案仅适用于版本1类型的函数,不适用于版本2