首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在RabbitMq中使用publishAsync时出现内部服务器错误

在RabbitMq中使用publishAsync时出现内部服务器错误
EN

Stack Overflow用户
提问于 2019-07-17 18:03:57
回答 2查看 266关注 0票数 0

我正在尝试使用RabbitMq构建一个消息代理,以及一个将命令发布到消息代理的API网关。但是当我使用post方法时,我总是得到一个500的状态码。

我查看了RabbitMq服务器的日志,它似乎对应用程序接口和微服务进行了身份验证,这些微服务应该根据发送的命令执行操作。我还将附加一个日志的图像。

//程序运行时的RabbitMq日志

代码语言:javascript
复制
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 '/'

PS。当有POST方法时,我得不到任何类型的日志。我还使用postman发送POST请求。

//这是接收命令的Controller

代码语言:javascript
复制
[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}");
        }
    }

//根据调试,我发现它在

await _busClient.PublishAsync(command);

是调用的。它不会将命令发送到消息代理。

//请求post命令时出现异常。

代码语言:javascript
复制
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)

我期望代码发送一个接受的代码,其中活动微服务应该根据发送的命令执行操作。现在,我只是尝试发送一个创建活动命令,然后活动微服务应该接收该命令并创建活动。这是我第一次使用这样的东西,并感谢任何类型的建议或反馈。

EN

回答 2

Stack Overflow用户

发布于 2019-07-17 18:31:46

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

RawRabbit serialization issue

票数 0
EN

Stack Overflow用户

发布于 2021-08-04 06:25:13

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57073353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档