diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj index b7b0256..d1cee39 100644 --- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj +++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj @@ -11,6 +11,7 @@ + diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs index 5bcd6dc..f54647c 100644 --- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs +++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs @@ -25,6 +25,8 @@ public class InterfaceForwardApiModule : FakeModule { options.ScanApplicationServices(); }); + + services.AddMvc().AddNewtonsoftJson(); services.AddFakeSwaggerGen() .AddFakeExceptionFilter() diff --git a/src/InterfaceForward.Api/appsettings.json b/src/InterfaceForward.Api/appsettings.json index 83e47b6..9e05169 100644 --- a/src/InterfaceForward.Api/appsettings.json +++ b/src/InterfaceForward.Api/appsettings.json @@ -32,7 +32,7 @@ }, "FeiShuNotice": { "Title": "InterfaceForward-Dev", - "Webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/255c44ff-5891-4902-9b6a-6d0250e745f7", + "Webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/e5ced977-a616-42ce-8684-c7628e71b35e", "Timeout": 20 }, "Redis": { diff --git a/src/InterfaceForward.Application/Rabbit/RabbitClient.cs b/src/InterfaceForward.Application/Rabbit/RabbitClient.cs index 5937ae0..2a8b0ec 100644 --- a/src/InterfaceForward.Application/Rabbit/RabbitClient.cs +++ b/src/InterfaceForward.Application/Rabbit/RabbitClient.cs @@ -19,8 +19,9 @@ public class RabbitClient( if (!channelAccessor.IsNew) return; var channel = channelAccessor.Channel; + var decl = new DefaultDeclaration(channel); - consumeOptions.Declaration.Invoke(channel); + consumeOptions.Declaration.Invoke(decl); if (consumeOptions.FetchCount > 0) { @@ -82,5 +83,60 @@ public class ConsumeOptions public bool FailedRequeue { get; set; } - public Action Declaration { get; set; } -} \ No newline at end of file + public Action Declaration { get; set; } +} + + +public interface IDeclaration +{ + void QueueDeclare(string queue, bool durable, bool autoDelete = false, bool exclusive = false, + IDictionary arguments = null); + + void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete = false, + IDictionary arguments = null); + + void QueueBind(string queue, string exchange, string routingKey, + IDictionary arguments = null); +} + +public class DefaultDeclaration : IDeclaration +{ + private readonly IModel _chnl; + + // ReSharper disable once ConvertToPrimaryConstructor + public DefaultDeclaration(IModel chnl) + { + _chnl = chnl; + } + + public void QueueDeclare(string queue, bool durable, bool autoDelete = false, bool exclusive = false, + IDictionary arguments = null) + { + _chnl.QueueDeclare( + queue: queue, + durable: durable, + autoDelete: autoDelete, + exclusive: exclusive, + arguments: arguments); + } + + public void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete = false, + IDictionary arguments = null) + { + _chnl.ExchangeDeclare( + exchange: exchange, + type: type, + durable: durable, + autoDelete: autoDelete, + arguments: arguments); + } + + public void QueueBind(string queue, string exchange, string routingKey, IDictionary arguments) + { + _chnl.QueueBind( + queue: queue, + exchange: exchange, + routingKey: routingKey, + arguments: arguments); + } +}