I wrote consumer producer Solution in .NET Core, the weird thing is that I can consume messages only if my producer is in the same Project, If the producer is in different project\Solution, the message somewhat goes to "My_Queue_skipped" Queue.
Here is my Consumer Project Code:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
var bas = InitBus();
services.AddSingleton<IBus>(s => bas);
services.AddSingleton<IBusControl>(s => bas);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime, IServiceProvider serviceProvider)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
var bus = serviceProvider.GetRequiredService<IBusControl>();
bus.Start();
lifetime.ApplicationStopping.Register(() => bus.Stop());
}
private IBusControl InitBus()
{
return Bus.Factory.CreateUsingRabbitMq(sbc =>
{
Uri rabbitUri = new Uri("rabbitmq://rabbitmq_service");
var host = sbc.Host(rabbitUri, h =>
{
h.Username("guest");
h.Password("guest");
});
sbc.ReceiveEndpoint(host, "My_Queue",
e => { e.Consumer(() => new TestConsumer()); });
});
and this is my producer code:
var address = new Uri("rabbitmq://rabbitmq_service/My_Queue");
IRunNowQueueRequest flowRequest = new RunNowQueueRequest("7484b8e1-3b11-4ef9-8201-68f12384292d", "sss");
IRequestClient<IRunNowQueueRequest, IResponse> client =
_bus.CreateRequestClient<IRunNowQueueRequest, IResponse>(address, TimeSpan.FromSeconds(120));
IResponse response = await client.Request(flowRequest);
In case the same consumer is in the project of the producer, is gets the message Any ideas why this weird thing is happening?
Are you using a shared message contract assembly or defining the message type in each project?
Message types must match entirely, including namespace+{class|interface}name. If they don't match, your message contract won't match, and it will move the message to the skipped queue.
Most people create a separate assembly with the message contracts (interfaces, if they're smart) and publish it as a separate NuGet package.
Thanks, That was the problem
Please add this to the docs under troubleshooting or faq, seems something everyone will face the first time
It's been there, right at the top, highlighted, for a long time.
Most helpful comment
It's been there, right at the top, highlighted, for a long time.
https://masstransit-project.com/usage/messages.html