简体   繁体   English

C# Azure 事件网格发布 EventGridTopicEvent

[英]C# Azure Event Grid publish EventGridTopicEvent

I have scenario where I need to publish "EventGridTopicEvent" data and at the same time I need to store this event information in the Azure Storage Table.我有一个场景,我需要发布“EventGridTopicEvent”数据,同时我需要将此事件信息存储在 Azure 存储表中。 I would like to know is there any way to get the information(like T/F) if Publish event successfully done or not(any error), If it is published successfully then only I should save the data into Table storage.我想知道如果发布事件是否成功完成(任何错误),是否有任何方法可以获取信息(如 T/F),如果发布成功,那么只有我应该将数据保存到表存储中。

I need to handle the above logic via C# Event Handler(Mediator), I tried with C# TransactionScope but it is not having mechanism like Rollback. If event is not published then rollback the event as well as not store anything in the table storage or I should not make a call to handle the database transaction.

I have also tried _mediator.Publish(request).IsCompletedSuccessfully but it is giving true always even though I pass invalid request data.

code snippet
public async Task<Result<Response<XYZ>>> Handle(EventGridTopicEvent request, CancellationToken cancellationToken)
{
using TransactionScope transactionScope = new TransactionScope();
{
try
{
bool eventPublishStatus = _mediator.Publish(request).IsCompletedSuccessfully;
if (eventPublishStatus)
{
//Insert request data to Table storage
}}}}

I have scenario where I need to publish "EventGridTopicEvent" data and at the same time I need to store this event information in the Azure Storage Table.我有一个场景,我需要发布“EventGridTopicEvent”数据,同时我需要将此事件信息存储在 Azure 存储表中。 I would like to know is there any way to get the information(like T/F) if Publish event successfully done or not(any error), If it is published successfully then only I should save the data into Table storage.我想知道如果发布事件是否成功完成(任何错误),是否有任何方法可以获取信息(如 T/F),如果发布成功,那么只有我应该将数据保存到表存储中。

What do you mean with the publish event being succesfully done or not?发布事件是否成功完成是什么意思?

  • If you mean it is published to the Event Grid, then it is easy: when the call to the Event Grid SDK is completed without an exception the data is published to the Event Grid succesfully.如果您的意思是它发布到事件网格,那么很容易:当对事件网格 SDK 的调用毫无例外地完成时,数据将成功发布到事件网格。
  • If you want to know whether all the consumers of the event did get the data and processed it succesfully then you have a challenge there.如果您想知道事件的所有消费者是否确实获得了数据并成功处理了数据,那么您将面临挑战。

Within the context of your application it is hard to tell if all the consumers got the event and processed it as the Event Grid is an asynchronous eventing platform.在您的应用程序的上下文中,很难判断是否所有消费者都收到了事件并对其进行了处理,因为事件网格是一个异步事件平台。 If it fails to deliver the event it will retry it for some time and after that the event can be transferred to a dead letter store ( see the docs ).如果它未能传递事件,它将重试一段时间,然后可以将事件转移到死信存储( 请参阅文档)。 In reality this means that there can be a delay between the data being published and the data being consumed.实际上,这意味着在发布数据和使用数据之间可能存在延迟。 Given that, you can easily see how difficult it would be for your application to know all data is received and processed succesfully.鉴于此,您可以轻松地看到您的应用程序要知道所有数据都已成功接收和处理是多么困难。

If you want to store the data as some kind of log of what data is succesfully published to the event grid you might actually create a subscription to the event grid and use that to store the published data in the table storage.如果您想将数据存储为某种数据成功发布到事件网格的日志,您实际上可能会创建对事件网格的订阅,并使用该订阅将发布的数据存储在表存储中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM