I’ve tried to setup NServiceBus in a WebApp with the DataBus feature to no avail. This is what I have in terms of configuration of the bus,
_containerProvider.Register(Component.For<IProducer>()
.UsingFactoryMethod(() => new NServiceBusProducer(() => Configure
.WithWeb()
.DefaultBuilder()
//.AsMasterNode()
.Log4Net()
.MsmqTransport()
.IsTransactional(false) // ??
.PurgeOnStartup(false)
.UnicastBus()
.DefiningMessagesAs(t => t.Namespace != null && t.Namespace == "Magma.CommunicationBus.Messages")
.JsonSerializer()
.FileShareDataBus(@"..\..\..\abc")
//.CreateBus()
//.Start()))
.SendOnly()))
.LifestyleSingleton());
I don’t know if it’s a permission problem when NServiceBus is creating the storage folder, but I can’t even see that the DataBus is initializing. On the ‘listening’ side I can see this with this string in the output:
- File share data bus started. Location: …
But I can’t see this in the WebApp output. Also, when NServiceBus is initializing I can see (again in the output) a list of mutators that the bus is using. And again there is no trace of the ‘DataBusMessageMutator’
FYI I’m using this to send email attachments. This is how I do this:
message.Attachements = new DataBusProperty<byte[]>(email.Attachments.Select(a =>
{
using (MemoryStream ms = new MemoryStream())
{
a.ContentStream.CopyTo(ms);
return ms.ToArray();
}
}).First());
I’m trying with only 1 but I’m planning to send a list of attachments.
I can’t make this working on the ‘sending’ side. Of course it crashes in the ‘listening’ side somewhere in the NServiceBus code when the mutator tries to get the non-existing header to construct the file path of the ‘thing’ it will read. It crashes in the ‘Get’ method of the ‘FileShareDataBus’ class because the ‘key’ parameter is null in the ‘Path.Combine’ call.
What am I doing wrong or missing?
Well I guess I found the answer. You seem to need to implement the I(Message|Command|Event) interface in order for the databus to work properly. Also, you can send list of items by using something like:
I’m using this to send multiple attachments to an email message.
But I’m still curious as to why it didn’t work with the unobtrusive mode. I hope that the NServiceBus people see this question and explain this.