简体   繁体   中英

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.

I have tried to just send an array of Notification objects instead of just the one object but this doesn't seem to work.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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