【发布时间】:2018-10-01 23:47:27
【问题描述】:
目前是否可以从 Azure 函数将消息推送到 IAsyncCollector 主题输出并设置会话 ID?我的主题真的是 FIFO 排序,所以我们不得不设置会话。正因为如此,我们想象只是将 Guid 设置为唯一的会话 id。我知道如何通过此输出将消息推送到我的主题,但由于我们没有明确设置会话 ID,因此当然会出错。当我们将其发送到 IAsyncCollector 时,是否可以在代码中的某个位置进行设置?
这就是我们所拥有的,
[FunctionName("AccountCreatedHook")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req,
TraceWriter log, [ServiceBus("topic-name", Connection = "busname", EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Topic)] IAsyncCollector<AccountEventDTO> accountCreatedTopic)
{
log.Info("C# HTTP trigger function processed a request.");
// Get request body
var accountEvent = await req.Content.ReadAsAsync<AccountEventDTO>();
var payload = req.Content.ReadAsStringAsync().Result;
if (accountEvent != null && accountEvent.Name != null)
{
await accountCreatedTopic.AddAsync(accountEvent);
return req.CreateResponse(HttpStatusCode.OK, "Account successfully added to topic.");
}
return req.CreateResponse(HttpStatusCode.BadRequest, "Account was not formed well.");
}
【问题讨论】:
标签: c# azure azure-functions azureservicebus azure-servicebus-topics