- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个从服务器接收数据的 gRPC 客户端。客户端作为 Azure WebJob 运行。
接收到的数据看起来每条消息都有一个重放 ID。我目前将此重播 ID 作为文件存储在本地。收到的重播 ID 会附加到文件中。需要重播 ID,以便在出现问题时可以从该 ID 继续。
如果我在本地运行客户端,这不是问题,但我认为作为 WebJob 并不理想。我当前的问题是,在运行时创建/修改的文件存储在这里:
C:\local\Temp\jobs\continuous\SalesforceIngestor.App\ev4ygzfw.ezh
如果 WebJob 由于任何原因重新启动,replayIdStorage.txt 文件中的数据将会丢失。
是否有任何方法可以安全地将数据存储在 WebJob 中,以便重新启动后可以检索数据?
或者 Azure Blob 存储是更好的选择吗?
最佳答案
我尝试了以下 .Net Web 作业代码,并且能够将 Web 应用程序的 Web 作业数据存储在我的存储帐户容器中。
代码:
Program.cs:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
namespace WebJob1
{
internal class Program
{
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
host.RunAndBlock();
}
}
}
函数.cs:
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.IO;
namespace WebJob1
{
public class Functions
{
private const string ConnectionStringName = "AzureWebJobsStorage";
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
log.WriteLine(message);
string replayId = GenerateReplayIdFromMessage(message);
StoreReplayIdInBlobStorage(replayId);
}
private static string GenerateReplayIdFromMessage(string message)
{
return Guid.NewGuid().ToString();
}
private static void StoreReplayIdInBlobStorage(string replayId)
{
var storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable(ConnectionStringName));
var blobClient = storageAccount.CreateCloudBlobClient();
var containerName = "replayids";
var container = blobClient.GetContainerReference(containerName);
container.CreateIfNotExists();
var blobName = "replayIdStorage.txt";
var blob = container.GetBlockBlobReference(blobName);
blob.UploadText(replayId);
}
}
}
应用程序配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
<!-- For local execution, the value can be set either in this config file or through environment variables -->
<add name="AzureWebJobsDashboard" connectionString="<storage_connec_string>" />
<add name="AzureWebJobsStorage" connectionString="<storage_connec_string>" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
输出:
运行成功如下,
我在 Azure 门户的存储帐户中创建了两个容器,如下所示,
我在azure-webjobs-hosts容器中获得了Id,如下所示,
并在azure-jobs-host-output容器中,
然后,我将我的代码发布到网络应用,如下所示,
它已成功发布到Azure Portal的网络应用中的网络作业。然后,我单击运行开始运行网络作业,如下所示,
Web 作业运行已成功启动,如下所示,
然后,我在我的存储帐户azure-jobs-host-output容器中存储了网络应用详细信息,如下所示,
关于c# - 将数据存储在 Azure WebJob 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76613629/
我有一个 Azure WebJob,我正在从 visual studio 2017 发布到标准 S1 应用服务,WebJob 应该由 CRON 触发,但始终发布为连续,我无法弄清楚我做错了什么(另外两
我需要在计划的时间段内为不同的用户运行一项作业(例如 CRM 同步)。此同步由 ServiceBus 队列上的另一个函数放置的消息触发,该函数每 30 分钟由 TimerTrigger 触发一次。 现
我需要在计划的时间段内为不同的用户运行一项作业(例如 CRM 同步)。此同步由 ServiceBus 队列上的另一个函数放置的消息触发,该函数每 30 分钟由 TimerTrigger 触发一次。 现
我无法将计划的 Web 作业发布到 Azure 应用服务。我正在使用 Visual Studio 2017。 使用此设置一切正常: { "$schema": "http://schemastore.o
我计划使用连续的 Azure WebJob 发送电子邮件和推送通知。我了解 WebJobs 会因各种原因不时启动和停止。没关系,但我希望有机会在工作关闭之前“清理”一下。 这样我的 WebJob 可以
我已经看到了一些关于使用 settings.job 的指导。为此,但它不起作用 - 在控制台中我看到: WebJob singleton setting is False 如何防止横向扩展运行我的
我正在尝试部署一个触发的网络作业并使用 settings.json 文件安排它。我的 webapp 在 3 个实例中运行,所以我假设 webjob 将在 3 个实例中部署。因此,如果我使用带有 cro
我正在尝试找出是否有任何方法可以修改 webjobs sdk 重试策略。 现在,如果网络作业抛出异常,它会立即重新排队。这并不理想,特别是如果错误是由于数据库超时之类的原因造成的。 有谁知道该策略是否
我正在尝试部署一个触发的网络作业并使用 settings.json 文件安排它。我的 webapp 在 3 个实例中运行,所以我假设 webjob 将在 3 个实例中部署。因此,如果我使用带有 cro
我有一个启用了 Azure 持续交付的 Web 应用程序 (azure webapp)。这意味着每当我进行提交并将其推送到远程时,它都会自动构建应用程序并部署它。 我还有一些网络作业,我希望该过程也可
有没有办法从 MVC 应用程序中更改 webjob 的预定时间,或者是通过 azure 门户的唯一方法。 我不是指初始计划时间,而是在部署后通过 Mvc 应用程序中的 UI 更改计划时间。 最佳答案
Azure 提供了创建“触发式”WebJob 的可能性,例如每天都有时间表。 此外,还有 azure-webjobs-sdk-extensions( https://github.com/Azure/
我开始使用 WebJobs 来处理一些后台任务,但我遇到了关于错误处理和重试的问题。看来,如果我的任何函数是异步的,那么即使我在函数中抛出异常,该函数总是会在仪表板中报告成功。 考虑以下简单示例 ->
我们有一个带有“暂存”部署槽的 Azure 网站设置,我们使用连续的 Azure WebJob 来处理长时间运行的后台作业。看来,当您发布到网站(并包含 WebJob 二进制文件)时,如果 WebJo
我正在开发一个使用 TimerTrigger 的触发式网络作业. 在webjob停止之前,我需要处理一些对象,但我不知道如何触发“webjob停止”。 有了 NoAutomaticTrigger 函数
我正在处理一个网络作业,用于检查网络服务器的一些数据。有时网络服务器很忙,会在几秒钟后重试。 问题是,如果我只是忽略它并通过该函数,它将从队列中删除消息,我将无法重试调用。 我当前的解决方案(我一点也
我读过关于优雅关机的文章 here使用 WEBJOBS_SHUTDOWN_FILE 和 here使用取消 token ,所以我理解正常关闭的前提,但是我不确定它们将如何影响正在处理队列消息的 WebJ
如果运行webjob时出现任何异常或错误,我想释放所有对象。我如何知道是否发生错误。webjob 是否有任何错误触发器? 最佳答案 可以有两种方法来处理这个问题: 1) Try/Catch 方法:-
我在 AppService 中长时间运行 Web 作业(大约 1 小时)。AppService 已打开“始终打开”。 它的初始化是: var host = new JobHost(config); h
我在 AppService 中长时间运行 Web 作业(大约 1 小时)。AppService 已打开“始终打开”。 它的初始化是: var host = new JobHost(config); h
我是一名优秀的程序员,十分优秀!