fix:序列化器改为newtonsoft,取消队列独占模式

This commit is contained in:
xiaolipro 2025-07-26 15:00:52 +08:00
parent 259113ad1e
commit 57d21822a8
4 changed files with 63 additions and 4 deletions

View File

@ -11,6 +11,7 @@
<ProjectReference Include="..\InterfaceForward.Application\InterfaceForward.Application.csproj" />
<ProjectReference Include="..\InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj"/>
<PackageReference Include="Fake.Autofac" Version="8.0.0-preview12" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.18" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />

View File

@ -25,6 +25,8 @@ public class InterfaceForwardApiModule : FakeModule
{
options.ScanApplicationServices<InterfaceForwardApplicationModule>();
});
services.AddMvc().AddNewtonsoftJson();
services.AddFakeSwaggerGen()
.AddFakeExceptionFilter()

View File

@ -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": {

View File

@ -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<IModel> Declaration { get; set; }
}
public Action<IDeclaration> Declaration { get; set; }
}
public interface IDeclaration
{
void QueueDeclare(string queue, bool durable, bool autoDelete = false, bool exclusive = false,
IDictionary<string, object> arguments = null);
void ExchangeDeclare(string exchange, string type, bool durable, bool autoDelete = false,
IDictionary<string, object> arguments = null);
void QueueBind(string queue, string exchange, string routingKey,
IDictionary<string, object> 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<string, object> 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<string, object> arguments = null)
{
_chnl.ExchangeDeclare(
exchange: exchange,
type: type,
durable: durable,
autoDelete: autoDelete,
arguments: arguments);
}
public void QueueBind(string queue, string exchange, string routingKey, IDictionary<string, object> arguments)
{
_chnl.QueueBind(
queue: queue,
exchange: exchange,
routingKey: routingKey,
arguments: arguments);
}
}