Azure Durable Function 通过邮件发送 EventPostUri
Azure Durable Function Send EventPostUri by mail
我在 azure ad 中构建了一个用于用户配置的持久函数。
我的目标是检查可用许可证的编排功能。如果所有许可证都在使用中,函数将等待外部事件并重试许可证分配。
为了实现这一点,我想发送一封电子邮件,请求购买新许可证和“SendEventPostUri”。
我的问题是我找不到在编排函数中读取 SendEventPostUri 的方法。
这可能吗?
看来可以获取IDurableOrchestrationClient
接口的SendEventPostUri
via the CreateHttpManagementPayload
方法了
URI格式如下
http://host/runtime/webhooks/durabletask/instances/instanceId/raiseEvent/{eventName}?taskHub=TestHubName&connection=Storage&code=*****
并且您需要将 {eventName}
替换为您需要提出的事件。
这是我用来检查这个的示例代码
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
namespace csharp_durable_funk
{
public class RaiseEvent
{
[FunctionName("GetSendEventPostUriOrchestrator")]
public async Task<string> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
[DurableClient] IDurableOrchestrationClient durableClient,
ILogger log)
{
await context.CallActivityAsync("GetSendEventPostUriOrchestrator_Hello", null);
return durableClient.CreateHttpManagementPayload(context.InstanceId).SendEventPostUri;
}
[FunctionName("GetSendEventPostUriOrchestrator_Hello")]
public string SayHello([ActivityTrigger] string name, ILogger log)
{
return $"Hello {name}!";
}
[FunctionName("GetSendEventPostUri")]
public async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient durableClient,
ILogger log)
{
string instanceId = await durableClient.StartNewAsync("GetSendEventPostUriOrchestrator");
return await durableClient.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId);
}
}
}
我在 azure ad 中构建了一个用于用户配置的持久函数。 我的目标是检查可用许可证的编排功能。如果所有许可证都在使用中,函数将等待外部事件并重试许可证分配。
为了实现这一点,我想发送一封电子邮件,请求购买新许可证和“SendEventPostUri”。
我的问题是我找不到在编排函数中读取 SendEventPostUri 的方法。
这可能吗?
看来可以获取IDurableOrchestrationClient
接口的SendEventPostUri
via the CreateHttpManagementPayload
方法了
URI格式如下
http://host/runtime/webhooks/durabletask/instances/instanceId/raiseEvent/{eventName}?taskHub=TestHubName&connection=Storage&code=*****
并且您需要将 {eventName}
替换为您需要提出的事件。
这是我用来检查这个的示例代码
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
namespace csharp_durable_funk
{
public class RaiseEvent
{
[FunctionName("GetSendEventPostUriOrchestrator")]
public async Task<string> RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context,
[DurableClient] IDurableOrchestrationClient durableClient,
ILogger log)
{
await context.CallActivityAsync("GetSendEventPostUriOrchestrator_Hello", null);
return durableClient.CreateHttpManagementPayload(context.InstanceId).SendEventPostUri;
}
[FunctionName("GetSendEventPostUriOrchestrator_Hello")]
public string SayHello([ActivityTrigger] string name, ILogger log)
{
return $"Hello {name}!";
}
[FunctionName("GetSendEventPostUri")]
public async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient durableClient,
ILogger log)
{
string instanceId = await durableClient.StartNewAsync("GetSendEventPostUriOrchestrator");
return await durableClient.WaitForCompletionOrCreateCheckStatusResponseAsync(req, instanceId);
}
}
}