Есть ли способ отправить несколько уведомлений в NotificationHub с помощью Webjob SDK? - PullRequest
0 голосов
/ 13 мая 2019

Я настроил WebJob, который каждую минуту отправляет уведомление в NotificationHub для целей тестирования, и мне нужно, чтобы оно отправляло несколько уведомлений вместо одного.

Я пытался просто отправить массив объектов уведомлений вместо одного объекта, но, похоже, это не сработало.

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

Я пытаюсь сделать это неправильно?

Ответы [ 2 ]

0 голосов
/ 22 мая 2019

У меня нет представителя для комментариев, но я считаю, что согласно этой проблеме вышеупомянутое решение работает только с функциями типа версии 1, а не с версией 2

0 голосов
/ 19 мая 2019

Не уверен, что вы намеревались отправить этот фрагмент кода или нет, но я нашел оригинальный источник.

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

...