【问题标题】:Is there a way to send multiple notification to a NotificationHub with Webjob SDK?有没有办法使用 Webjob SDK 向 NotificationHub 发送多个通知?
【发布时间】:2019-05-13 08:11:34
【问题描述】:

我已经设置了一个 WebJob,它每分钟向 NotificationHub 发送一个通知以进行测试,我需要它来发送多个通知,而不仅仅是一个。

我尝试只发送一组 Notification 对象而不是一个对象,但这似乎不起作用。

函数.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);
        }
    }

我是否试图以错误的方式做到这一点?

【问题讨论】:

    标签: c# azure azure-webjobs azure-webjobssdk


    【解决方案1】:

    不确定您是否打算发送该代码 sn-p,但我找到了原始来源。

            // 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/ExtensionsSample/Samples/NotificationHubSamples.cs

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-02
        • 2017-01-06
        • 2020-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多