简体   繁体   English

有没有办法使用Webjob SDK向NotificationHub发送多个通知?

[英]Is there a way to send multiple notification to a NotificationHub with Webjob SDK?

I have set up a WebJob that sends a notification to a NotificationHub every minute for test purposes and I would need it to send multiple notifications instead of just the one. 我已经设置了一个WebJob,它每分钟都会向NotificationHub发送一个通知用于测试目的,我需要它发送多个通知而不是一个通知。

I have tried to just send an array of Notification objects instead of just the one object but this doesn't seem to work. 我试图只发送一个Notification对象数组而不只是一个对象,但这似乎不起作用。

Function.cs 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);
        }
    }

Am I trying to do this the wrong way ? 我试图以错误的方式做这件事吗?

Not sure if you meant to send that code snippet or not, but I found the original source. 不确定您是否打算发送该代码段,但我找到了原始来源。

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

See https://github.com/Azure/azure-webjobs-sdk-extensions/blob/migrate_notification_hubs/src/ExtensionsSample/Samples/NotificationHubSamples.cs 请参阅https://github.com/Azure/azure-webjobs-sdk-extensions/blob/migrate_notification_hubs/src/ExtensionsSample/Samples/NotificationHubSamples.cs

我没有代表评论,但我相信根据这个问题,上述解决方案只适用于版本1类型的功能,而不是版本2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM