Masstransit: Message not received by consumer

Created on 3 Aug 2019  路  1Comment  路  Source: MassTransit/MassTransit

Is this a bug report?

Probably.

Can you also reproduce the problem with the latest version?

Tested with version 5.5.4 and 5.5.5-develop

Environment

  1. Operating system: Windows 10
  2. Visual Studio version: VS 2019
  3. Dotnet version: .NET Core 3.0 preview-7

Steps to Reproduce

I have created two simple asp.net core applications. One acts as a consumer and the other one acts as producer.

  1. Start consumer app which connects to RabbitMQ
  2. Start producer app which sends message to RabbitMQ

Expected Behavior

Consumer application should receive message.

Actual Behavior

Message successfully hits RabbitMQ but is then moved to the skip queue. In consumer application debug message is printed: MassTransit.Messages: Debug: SKIP rabbitmq://localhost/test-queue 7a000000-9a3c-0005-69d4-08d717e81ed5

Reproducible Demo

Producer

using System;
using MassTransit;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace WebApplication1
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMassTransit(x =>
            {             
                x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    var host = cfg.Host(new Uri("rabbitmq://localhost"), hostConfigurator =>
                    {
                        hostConfigurator.Username("guest");
                        hostConfigurator.Password("guest");
                    });
                }));
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISendEndpointProvider sendEndpointProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }          

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    var endpoint = await sendEndpointProvider.GetSendEndpoint(new Uri("rabbitmq://localhost/test-queue"));

                    await endpoint.Send<CreateUser>(new {
                        MyName = "justmyname"
                    });

                    await context.Response.WriteAsync("Hello World!");
                });
            });
        }
    }

    public interface CreateUser
    {
        public string MyName { get; }
    }
}

Consumer

using System;
using System.Threading.Tasks;
using GreenPipes;
using MassTransit;
using MassTransit.AspNetCoreIntegration;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace WebApplication2
{
    public class Startup
    {
        private IConfiguration Configuration { get; }

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }


        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHealthChecks();

            //services.AddScoped<CreateUserConsumer>();

            // Register MassTransit
            services.AddMassTransit(x =>
            {
                x.AddConsumer<CreateUserConsumer>();


                x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    var host = cfg.Host(new Uri("rabbitmq://localhost"), hostConfigurator =>
                    {
                        hostConfigurator.Username("guest");
                        hostConfigurator.Password("guest");
                    });

                    cfg.ReceiveEndpoint(host, "test-queue", ep =>
                    {
                        ep.PrefetchCount = 16;
                        ep.UseMessageRetry(r => r.Interval(2, 100));

                        ep.ConfigureConsumer<CreateUserConsumer>(provider);
                    });
                }));
        });

            services.AddMassTransitHostedService();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHealthChecks("/health", new HealthCheckOptions { Predicate = check => check.Tags.Contains("ready") });

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello World!");
                });
            });
        }
    }

    public class CreateUserConsumer : IConsumer<CreateUser>
    {
        public async Task Consume(ConsumeContext<CreateUser> context)
        {
            Console.WriteLine($"Updating customer: {context.Message.MyName}");
            await Console.Out.WriteLineAsync($"Updating customer: {context.Message.MyName}");
        }
    }

    public interface CreateUser
    {
        public string MyName { get; set; }
    }
}

Most helpful comment

After hours of searching I've finally resolved this issue. Apparently, CreateUser in producer and consumer app must have same namespace.

>All comments

After hours of searching I've finally resolved this issue. Apparently, CreateUser in producer and consumer app must have same namespace.

Was this page helpful?
0 / 5 - 0 ratings