Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AddMasstransitHostedService cannot be found

Good day
I’m configuring Masstransit for .net6 net core application
Have added Masstransit nuget packages:

<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.2.4" />
<PackageReference Include="MassTransit.RabbitMQ" Version="7.2.4" />

Am registering it in Startup and it says there is no such method as AddMasstransitHostedService
I have tried publishing message without it, but no exchange is being created (and for some reason debug also shows actual address with port 0)

Would be very grateful for help
Have searched everything related on the internet, unfortunately no fixes yet

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the way I register Masstransit:

services.AddMassTransit(mt =>
{
    mt.UsingRabbitMq((context, cfg) =>
    {
        cfg.Host(new Uri(RabbitMqOptions.RabbitMqUri), h =>
        {
            h.Username(RabbitMqOptions.UserName);
            h.Password(RabbitMqOptions.Password);
        });
        
        cfg.AutoStart = true;

        cfg.Publish<IServerNotificationMessage>(e => e.ExchangeType = RabbitMQ.Client.ExchangeType.Direct);
    });
});
services.AddMassTransitHostedService();//<-----this one hints: IServiceCollection doesnt contain a definition for AddMassTransitHostedService...

and here is the way I’ve tried publishing message:

public class SomeController : ControllerBase
{
    protected readonly IBus _bus;

    public SomeController(IBus bus)
    {
        _bus = bus;
    }

    [HttpGet("TestPublish")]
    public void TestPublish(CancellationToken cancellationToken)
    {
        _bus.Publish<SomeMessage>(new
        {
            ...
            ... // fields go here
        }, cancellationToken);

>Solution :

You need to add the MassTransit.AspNetCore package reference.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading