using Util.Microservices.Dapr.Events;
using Util.Microservices.Dapr.WebApiSample.Events;
namespace Util.Microservices.Dapr.WebApiSample.Controllers;
///
/// 集成事件控制器
///
public class IntegrationEventController : IntegrationEventControllerBase {
///
/// 状态管理操作
///
private readonly IStateManager _stateManager;
///
/// 日志操作
///
private readonly ILogger _log;
///
/// 初始化集成事件控制器
///
public IntegrationEventController( IStateManager stateManager, ILogger log ) {
_stateManager = stateManager;
_log = log;
}
///
/// 订阅1
///
[HttpPost( "WebApi_Test1" )]
[Topic( nameof( TestEvent ) )]
public async Task Test1Async( TestEvent @event ) {
_log.LogInformation( "========================================================WebApi_Test1:{@TestEvent}", @event );
await _stateManager.StoreName( "event-state-store" ).AddAsync( $"webapi_{@event.Code}", @event );
return Success();
}
///
/// 订阅B
///
[HttpPost( "WebApi_B" )]
[Topic( "b" )]
public async Task TestBAsync( TestEvent @event ) {
_log.LogInformation( "========================================================WebApi_B:{@TestEvent}", @event );
await Task.CompletedTask;
return Success();
}
///
/// 订阅C
///
[HttpPost( "WebApi_C" )]
[Topic( "c" )]
public async Task TestCAsync( TestEvent @event ) {
_log.LogInformation( "========================================================WebApi_C:{@TestEvent}", @event );
await Task.CompletedTask;
throw new Exception( "WebApi_Exception_C" );
return Success();
}
}