using Util.Exceptions; using Util.Microservices.Dapr.Events; using Util.Microservices.Dapr.PubsubSample.Events; namespace Util.Microservices.Dapr.PubsubSample.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( "Pubsub_Test1" )] [Topic( nameof( TestEvent ) )] public async Task Test1Async( TestEvent @event ) { _log.LogInformation( "========================================================Pubsub_Test1:{@TestEvent}", @event ); await _stateManager.StoreName( "event-state-store" ).AddAsync( $"pubsub_{@event.Code}", @event ); return Success(); } /// /// 订阅B /// [HttpPost( "Pubsub_B" )] [Topic( "b" )] public async Task TestBAsync( TestEvent @event ) { _log.LogInformation( "========================================================Pubsub_B:{@TestEvent}", @event ); await Task.CompletedTask; return Success(); } /// /// 订阅C /// [HttpPost( "Pubsub_C" )] [Topic( "c" )] public async Task TestCAsync( TestEvent @event ) { _log.LogInformation( "========================================================Pubsub_C:{@TestEvent}", @event ); await Task.CompletedTask; throw new Warning( "Pubsub_Warning_C" ); return Success(); } }