致命错误 - 使用Service Fabric的Azure存储队列

时间:2018-02-16 01:55:26

标签: azure-service-fabric azure-webjobssdk azure-storage-queues

我一直在尝试为Service Fabric内部Azure存储队列上发布的消息添加侦听器。我在无状态服务中使用的代码片段如下:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Fabric;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
using Microsoft.WindowsAzure.Storage.Queue;
using Notification;

namespace My.Notification
{
    /// <summary>
    /// An instance of this class is created for each service instance by the Service Fabric runtime.
    /// </summary>'
    internal sealed class Notification : StatelessService
    {
        public Notification(StatelessServiceContext context)
            : base(context)
        {




        }

        /// <summary>
        /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests.
        /// </summary>
        /// <returns>A collection of listeners.</returns>
        protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return new ServiceInstanceListener[0];
        }

        //First option
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            JobHostConfiguration config = new JobHostConfiguration();
            config.DashboardConnectionString = "string";
            config.StorageConnectionString = "stringg";
            config.Queues.BatchSize = 10;
            config.Queues.MaxDequeueCount = 8;
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(30);
            var host = new JobHost(config);

            //Breaks below
            await host.CallAsync(typeof(Notification).GetMethod("ProcessMethod"), cancellationToken);
            host.RunAndBlock();

        }

        //Second option
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            try
            {
                var config = new JobHostConfiguration
                {
                    DashboardConnectionString = "string",//Real connection string,
                    StorageConnectionString = "string",
                    Queues =
                    {
                        BatchSize = 1,
                        MaxDequeueCount = 3,
                        MaxPollingInterval = TimeSpan.FromSeconds(30)
                    }
                };
                var host = new JobHost(config);

                //Breaks here
                await host.StartAsync(cancellationToken);
            }
            catch (Exception ex)
            {
                //ServiceEventSource.Current.ServiceStartupFailedEvent(ex.ToString());
                throw;
            }
        }

        [NoAutomaticTrigger]
        public static async Task ProcessMethod(CancellationToken cancellationToken)
        {
            long iterations = 0;
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();
                //log
                Trace.TraceInformation(">>[{0}]ProcessMethod Working-{1}", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"), ++iterations);
                //sleep for 5s
                await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
            }
        }


        //[Timeout("00:03:00")]
        public static void ProcessNotificationsInQueue([QueueTrigger("emailqueue")] string message)
        {
            Trace.TraceInformation(">ProcessNotificationsInQueue invoked with notification:{0}", message);
        }
    }
}

我得到的错误如下所示。我已经尝试了两种方式,我不知道如何获得除此之外的更多细节。有些帖子建议我们启用MDA,我也尝试过。其他人指出它可能是一个CLR问题。我也看过这个post here,我的默认设置几乎相同。

enter image description here

1 个答案:

答案 0 :(得分:1)

好的根据讨论找出解决方案here 我的Azure WebJobs版本依赖于Storage。 Storage的版本是9.0.0,其中删除了一个方法。该方法的不可用性是导致此崩溃的原因。