【问题标题】:Internal Server Error when using publishAsync in RabbitMq在 RabbitMq 中使用 publishAsync 时出现内部服务器错误
【发布时间】: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


    【解决方案1】:

    实际上,我需要做的就是更新我正在使用的 RawRabbitMq 版本。我将附上帮助我解决问题的帖子的链接。

    RawRabbit serialization issue

    【讨论】:

      【解决方案2】:

      更新 RawRabbit 的版本为我解决了以下问题

      System.MissingMethodException:找不到方法:'Void Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'

      【讨论】:

        猜你喜欢
        • 2015-05-29
        • 2021-10-07
        • 2014-02-15
        • 2020-08-18
        • 2019-03-21
        • 1970-01-01
        • 1970-01-01
        • 2016-06-23
        • 2023-03-10
        相关资源
        最近更新 更多