gpt4 book ai didi

azure - QueueTrigger 未选取消息 - Azure WebJobs SDK 3.0

转载 作者:行者123 更新时间:2023-12-03 04:13:41 24 4
gpt4 key购买 nike

我正在尝试使用 SDK 3.0.x 开发 WebJob,并在本地进行测试。我按照 github 中的示例进行操作,但没有成功。

在本地运行时,一切正常,它还会看到 ProcessQueueMessage 函数,但不会从队列中选取消息。

程序.cs

static void Main(string[] args)
{
var builder = new HostBuilder();
//builder.UseEnvironment(EnvironmentName.Development);
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();

});
builder.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
});

builder.ConfigureLogging((context, b) =>
{
b.AddConsole();

// If the key exists in settings, use it to enable Application Insights.
string instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(instrumentationKey))
{
b.AddApplicationInsights(o => o.InstrumentationKey = instrumentationKey);
}
});

builder.ConfigureServices((context, services) =>
{
//services.AddSingleton<IJobActivator, MyJobActivator>();
services.AddScoped<Functions, Functions>();
services.AddSingleton<IHostService, HostService>();
})
.UseConsoleLifetime();

var host = builder.Build();
using (host)
{
host.Run();
}
}

函数.cs

public class Functions
{
private readonly IHostService _hostService;

public Functions(IHostService hostService)
{
_hostService = hostService;
}
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public void ProcessQueueMessage([QueueTrigger("newrequests")] string dd,
//DateTimeOffset expirationTime,
//DateTimeOffset insertionTime,
//DateTimeOffset nextVisibleTime,
//string queueTrigger,
//string id,
//string popReceipt,
//int dequeueCount,
ILogger logger)
{
var newRequestItem = new RequestQueueItem();
logger.LogTrace($"New queue item received...");
//logger.LogInformation($" QueueRef = {id} - DequeueCount = {dequeueCount} - Message Content [Id = {newRequestItem.Id}, RequestDate = {newRequestItem.RequestDate}, Mobile = {newRequestItem.Mobile}, ProviderCode = {newRequestItem.ProviderCode}, ItemIDClass = {newRequestItem.MappingIDClass}]");
// TODO: Read the DatabaseConnectionString from App.config
logger.LogTrace($" Getting DB ConnectionString...");
var connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString;
// TODO: Initiation of provider service instance
logger.LogTrace($" Init IalbayanmtnclientserviceClient service instance...");
var bayanService = new AlbayanMtnWCFService.IalbayanmtnclientserviceClient();
// TODO: sending request to provider service endpoint and wait for response
logger.LogTrace($" Sending request to Service Endpoint...");
var response= bayanService.requestpaymenttransactionAsync("agentcode", "agentpassword", "accountno", int.Parse(newRequestItem.TransactionType), newRequestItem.MappingIDClass, newRequestItem.Mobile, (int)newRequestItem.Id).Result;

logger.LogTrace($"Done processing queue item");
}
}

这是输出的屏幕截图

enter image description here

感谢您的帮助

队列消息“newrequests”的屏幕截图

enter image description here

最佳答案

从您的快照来看,您的网络作业在本地运行良好。它没有选择消息,因为您没有在 newrequests 队列中添加消息。

该功能只有在添加消息后才会触发。否则我会得到和你一样的结果。

enter image description here

关于教程,可以引用官方文档:Get started with the Azure WebJobs SDK 。并确保设置正确的存储帐户。下面是我的 appsettings.json。确保 appSettings.json 文件的“复制到输出目录”属性设置为如果较新则复制始终复制。否则会遇到异常:存储帐户“存储”未配置。

{
"ConnectionStrings": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=key;..."
}
}

希望这可以帮助您,如果您还有其他问题,请告诉我。

关于azure - QueueTrigger 未选取消息 - Azure WebJobs SDK 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54950494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com