【问题标题】:Azure Web Jobs Redis (RedLock) & Blob Storage Access IssuesAzure Web Jobs Redis (RedLock) 和 Blob 存储访问问题
【发布时间】:2017-10-16 11:08:13
【问题描述】:

我们切换到 WebJobs,我们的后台任务在新项目进入 Azure 队列时开始工作。现在我们有一些奇怪的问题,他似乎在访问 Redis RedLock 和 Storage 时遇到了我无法解释的问题。

现在我们遇到的最大问题是 RedLock。我们正在使用 RedLock.Net 进行分布式锁定。现在这在我们的生产 Web 应用程序中一切正常,它也适用于我们拥有的后台工作人员,但是一旦我们切换到 WebJobs,他基本上无法获得锁。用一些代码来支持这一点......我们像这样锁定:

        using (var redisLock = await _redLockConnection.RedisLockFactory.CreateAsync(resource, UserLockExpiryTime, UserLockWaitTime, UserLockRetryTime))
        {
            // make sure we got the lock
            if (redisLock.IsAcquired)
            {
                // execute code...
            }
            else
            {
                throw new CouldNotAcquireRedLockException();
            }
        }

这里的问题是,IsAcquired 在 Webjob 中总是错误的,我不知道为什么!?

可能与此问题有关的第二件事是删除 azure 存储中的 blob 文件,该文件仅在 WebJob 中出现 404 失败。

var file = _blobContainer.GetBlockBlobReference("file.txt");
file?.Delete();

这将失败,并在 WebJob 中出现 404 Not found 异常。

我在设置网络作业时有什么遗漏吗?这可能是写操作的访问问题吗?很高兴得到任何帮助!

【问题讨论】:

  • deleting a blob file in azure storage that fails with a 404 only within a WebJob 请通过 Azure 门户或 Azure 存储资源管理器检查 Blob 是否存在,或调用 Exists method 以检查 Blob 是否存在。

标签: azure-storage azure-webjobs redlock.net


【解决方案1】:

IsAcquired 在 Webjob 中始终为 false

我在 Azure WebJob 中使用 RedLock.net 对以下代码进行了测试,如果锁定可用,我可以获得资源锁定。

public static void ProcessQueueMessage([QueueTrigger("mymes")] string message, TextWriter log)
{
    var azureEndPoint = new RedisLockEndPoint
    {
        EndPoint = new DnsEndPoint("{YOUR_CACHE}.redis.cache.windows.net", 6380),
        Password = "YOUR_ACCESS_KEY",
        Ssl = true
    };

    var eps = new[] { azureEndPoint };


    var rlf = new RedisLockFactory(eps);

    var resource = "https://{storageaccount}.blob.core.windows.net/{containername}/test.txt";
    var expiry = TimeSpan.FromSeconds(50);
    var wait = TimeSpan.FromSeconds(10);
    var retry = TimeSpan.FromSeconds(1);

    using (var redisLock = rlf.Create(resource, expiry, wait, retry))
    {
        Console.WriteLine("Lock acquired: " + redisLock.IsAcquired);
    }

    log.WriteLine(message);
}

测试结果:

删除 azure 存储中失败并显示 404 的 blob 文件

正如我在评论中提到的,请通过 Azure 门户或 Azure 存储资源管理器检查该 Blob 是否存在,或在删除之前致电 Exists method 以检查该 Blob 是否存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-03
    • 2021-12-18
    • 2021-11-19
    • 2019-10-13
    • 2013-01-28
    • 2012-09-30
    • 1970-01-01
    • 2018-10-26
    相关资源
    最近更新 更多