In my application I'm configuring Producer with Rabbitmq. my configuration looks like below
using (var adapter = new BuiltinHandlerActivator())
{
Configure.With(adapter)
.Logging(l => l.ColoredConsole(LogLevel.Warn))
.Transport(t => t.UseRabbitMqAsOneWayClient(connection))
.Routing(r => r.TypeBased().MapAssemblyOf<TestClass>(queueName))
.Start();
await adapter.Bus.Publish(new TestClass() { Name = "TestName123" });
}
Where in there are many other Dtos i want to map just like TestClass. Can i specify namespace/assembly in Routing(..)? So that all the objects/dtos under that namespace are mapped? Other classes are as below
public class TestClass
{
public String Name { get; set; }
public String Date { get; set; }
}
public class NewTest
{
public string Name { get; set; }
}
On other side I'm useing WindsorContainer and it looks like below
public class Handle : IHandleMessages<TestClass>,IHandleMessages<NewTest>
{
Task IHandleMessages<TestClass>.Handle(TestClass message)
{
return null;
}
Task IHandleMessages<NewTest>.Handle(NewTest message)
{
return null;
}
}
CodePudding user response:
When you
await bus.Publish(new TestClass(...));
you don't have to map anything, as PUBLISHING with Rebus will distribute a copy of the event message to anyone who subscribed.
Therefore, to receive the published instance of TestClass
, your subscribers simply need to
await bus.Subscribe<TestClass>();
This will create the necessary bindings in RabbitMQ, making it so that all published events of that type will be distributed to the subscribers.
I encourage you to go to your RabbitMQ's management console (usually hosted on http://<rabbitmq-hostname>:15672
) and see what the topology looks like before/after subscribing.