我正在尝试使用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 '/'
PS。有POST方法时,我没有任何日志。我也在用邮递员发送POST请求。
//这是接收命令的控制器
[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);
被调用。没有将命令发送到消息代理的地方。
//例外,当请求post命令时,我得到了提示。
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)
我希望代码发送一个“接受的”代码,“活动”微服务应根据发送的命令采取行动。现在,我只是尝试发送create activity命令,然后Activity Microservice应该接收该命令并创建活动。这是我第一次使用这种东西,希望能收到任何建议或反馈。
答案 0 :(得分:0)
实际上,我要做的就是更新我正在使用的RawRabbitMq的版本。我将在该帖子上附加一个链接,以帮助我解决问题。
答案 1 :(得分:0)
更新 RawRabbit 的版本为我解决了以下问题
System.MissingMethodException: Method not found: 'Void Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'