【发布时间】:2023-03-03 04:46:01
【问题描述】:
我正在尝试使用 RabbitMq 构建消息代理,以及将命令发布到消息代理的 API 网关。但是在使用 post 方法时,我不断收到 500 的状态码。
我查看了 RabbitMq 服务器的日志,它似乎对 API 和应该对发送的命令起作用的微服务进行了身份验证。我还会附上日志的图像。
// 运行程序时的 RabbitMq 日志
2019-07-17 12:31:24.698 [info] <0.478.0> accepting AMQP connection <0.478.0> ([::1]:64476 -> [::1]:5672)
2019-07-17 12:31:24.773 [info] <0.478.0> connection <0.478.0> ([::1]:64476 -> [::1]:5672): user 'guest' authenticated and granted access to vhost '/'
2019-07-17 12:31:26.960 [info] <0.485.0> accepting AMQP connection <0.485.0> ([::1]:64479 -> [::1]:5672)
2019-07-17 12:31:27.032 [info] <0.485.0> connection <0.485.0> ([::1]:64479 -> [::1]:5672): user 'guest' authenticated and granted access to vhost '/'
附言。当有 POST 方法时,我没有得到任何类型的日志。我也在使用邮递员发送 POST 请求。
//这是接收命令的Controller
[Route("[controller]")]
public class ActivitiesController : Controller
{
private readonly IBusClient _busClient;
public ActivitiesController(IBusClient busClient)
{
_busClient = busClient;
}
[HttpPost("")]
public async Task<IActionResult> Post([FromBody]CreateActivity command)
{
if (command == null)
throw new ArgumentNullException(nameof(command), "Command can not be null.");
command.Id = Guid.NewGuid();
command.CreatedAt = DateTime.UtcNow;
await _busClient.PublishAsync(command);
return Accepted($"activities/{command.Id}");
}
}
//根据调试发现它在
之后发送了一个500状态码await _busClient.PublishAsync(command);
被调用。它没有向消息代理发送命令。
// 请求发布命令时出现异常。
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:Error: An unhandled exception has occurred while executing the request.
System.MissingMethodException: Method not found: 'Void Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'.
at RawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension.<>c.<AddRawRabbit>b__0_1(IDependencyResolver resolver)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass4_0`2.<AddSingleton>b__0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
--- End of stack trace from previous location where exception was thrown ---
at System.Lazy`1.CreateValue()
at RawRabbit.DependencyInjection.SimpleDependencyInjection.TryGetService(Type serviceType, Object& service, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass9_0.<CreateInstance>b__4(ParameterInfo parameter)
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.CreateInstance(Type implementationType, IEnumerable`1 additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<AddTransient>b__2_0[TService,TImplementation](IDependencyResolver resolver)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.TryGetService(Type serviceType, Object& service, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass9_0.<CreateInstance>b__4(ParameterInfo parameter)
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.CreateInstance(Type implementationType, IEnumerable`1 additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<AddTransient>b__2_0[TService,TImplementation](IDependencyResolver resolver)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.TryGetService(Type serviceType, Object& service, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass9_0.<CreateInstance>b__4(ParameterInfo parameter)
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.CreateInstance(Type implementationType, IEnumerable`1 additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional)
at RawRabbit.Pipe.PipeBuilder.CreateInstance(MiddlewareInfo middlewareInfo)
at RawRabbit.Pipe.PipeBuilder.Build()
at RawRabbit.BusClient.InvokeAsync(Action`1 pipeCfg, Action`1 contextCfg, CancellationToken token)
at Actio.Api.Controllers.ActivitiesController.Post(CreateActivity command) in C:\Source\Actio\src\Actio.Api\Controllers\ActivitiesController.cs:line 27
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at System.Threading.Tasks.ValueTask`1.get_Result()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
我期望代码发送一个接受的代码,活动微服务应根据发送的命令采取行动。现在,我只是尝试发送一个创建活动命令,然后活动微服务应该接收该命令并创建活动。这是我第一次使用这样的东西,如果有任何建议或反馈,我将不胜感激。
【问题讨论】:
标签: c# asp.net .net-core rabbitmq microservices