我有基于.NET Core2.2的微服务。我使用RawRabbit (Version2.0.0-beta9)作为服务总线。它安装了下列软件包:
<PackageReference Include="RawRabbit" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.DependencyInjection.ServiceCollection" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.Operations.Publish" Version="2.0.0-beta9" />
<PackageReference Include="RawRabbit.Operations.Subscribe" Version="2.0.0-beta9" />这就是我的控制器的样子:
private readonly IBusClient _busClient;
//...constructor that inits the _busClient
[HttpPost("")]
public async Task<IActionResult> Post([FromBody] CreateActivity model)
{
model.Id = Guid.NewGuid();
await _busClient.PublishAsync(model); //Exception thrown here
return Accepted($"Activities/{model.Name}");
}当代码试图执行以下操作时,会出现此问题:
await _busClient.PublishAsync(model);我得到的例外是:
Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'.:MissingMethodException:方法未找到:'Void MissingMethodExceptionRawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension+<>c.b___1(IDependencyResolver解析器) .更多的文字..。 Actio.Api.Controllers.ActivitiesController.Post(CreateActivity模型中的RawRabbit.BusClient.InvokeAsync(Action,Action,CancellationToken令牌) 后面跟着我的Post动作代码,如上面所示。
下列行动如预期那样起作用:
[HttpGet]
public IActionResult Get()
{
return Content("Hello from Actio API!");
}我认为这是因为这个动作不使用IBusClient。所以,问题必须是在RawRabbit。我在谷歌上搜索了这个问题,并在RawRabbit GitHub回购上发现了一个问题。解决方案是升级到RawRabbit上的更新版本。因此,我尝试升级到2.0.0-rc1,但是我遇到了一些语法错误。我定义了一个类Extensions,它定义了以下方法:
public static Task WithCommandHandlerAsync<TCommand>(this IBusClient bus,
ICommandHandler<TCommand> handler) where TCommand: ICommand
=> bus.SubscribeAsync<TCommand>(msg => handler.HandleAsync(msg),
ctx => ctx.UseConsumerConfiguration(cfg =>
cfg.FromDeclaredQueue(q => q.WithName(GetQueueName<TCommand>()))));问题似乎在于UseConsumerConfiguration。错误说:
ISubscribe上下文不包含UseConsumerConfiguration的定义
附加信息:我正在学习.NET微服务课程,由Packt出版。对于完全相同的包,这段代码似乎运行得很好。
发布于 2020-03-15 23:37:40
对于将来的任何人来说,你必须做以下事情:
最后的输出应该如下所示:
public static Task WithCommandHandlerAsync<TCommand>(this IBusClient bus,
ICommandHandler<TCommand> handler) where TCommand : ICommand
=> bus.SubscribeAsync<TCommand>(msg => handler.HandleAsync(msg),
ctx => ctx.UseSubscribeConfiguration(cfg =>
cfg.FromDeclaredQueue(q => q.WithName(GetQueueName<TCommand>()))));发布于 2019-06-14 21:05:31
将RawRabbit版本更新为2.0.0-rc5
之后,使用UseSubscribeConfiguration而不是UseConsumerConfiguration
https://stackoverflow.com/questions/55836995
复制相似问题