1

I have microservice based on .NET Core 2.2. I am using RawRabbit (version 2.0.0-beta9) as the service bus. The following packages were installed with it:

<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" />

This is what my controller looks like:

    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}");
    }

The problem occurs when the code tries to do the following:

await _busClient.PublishAsync(model);

The exception I get is:

MissingMethodException: Method not found: 'Void Newtonsoft.Json.JsonSerializer.set_TypeNameAssemblyFormat(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle)'. RawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension+<>c.b__0_1(IDependencyResolver resolver)

....... more text .......

RawRabbit.BusClient.InvokeAsync(Action pipeCfg, Action contextCfg, CancellationToken token) Actio.Api.Controllers.ActivitiesController.Post(CreateActivity model) in ActivitiesController.cs

followed by the code of my Post action as showed above.

The following action works as expected:

    [HttpGet]
    public IActionResult Get()
    {
        return Content("Hello from Actio API!");
    }

I assumed it's because this action does not use the IBusClient. So, the problem had to be with RawRabbit. I googled the issue and found an issue on the RawRabbit GitHub repo. The solution was to upgrade to a newer version on RawRabbit. So, I tried upgrading to 2.0.0-rc1 but I got some syntax errors. I have defined a class Extensions that defines the following method:

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>()))));

The problem seems to be with UseConsumerConfiguration. The error says:

ISubscribe Context does not contain a definition for UseConsumerConfiguration

Additional info: I am following the .NET Microservices Course by Packt Publishing. This code seems to be working fine for them with the exact same packages.

hkjhadj1
  • 848
  • 3
  • 13
  • 32

2 Answers2

4

For anyone in the future, you have to do the following:

  1. RawRabbit 2.0.0-rc5 (latest at the time of writing). Include Prelease versions.
  2. Change UseConsumerConfiguration -> UseSubscribeConfiguration
  3. Install RawRabbit.Operations.Subscribe because SubscribeAsync will no longer be recognized

Final output should look like this:

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>()))));
Echen
  • 179
  • 8
  • It worked for me by updating all RawRabbit packages in Action.Common.csproj to the latest version (2.0.0-rc5) and following steps 2 and 3. – mavi Apr 08 '20 at 17:31
0

Update RawRabbit version to 2.0.0-rc5

After that use UseSubscribeConfiguration instead of UseConsumerConfiguration