【问题标题】:Fatal Error - Azure Storage Queues with Service Fabric致命错误 - 使用 Service Fabric 的 Azure 存储队列
【发布时间】:2018-02-16 01:55:25
【问题描述】:

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

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,我有几乎相同的默认设置。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 1970-01-01
      • 2017-04-17
      • 2018-01-25
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多