I ran into a strange issue with publishing events to MSMQ using NServiceBus. I can successfully send messages using IBus.Send
method (I can find the sent messages in MSMQ). However, when I try to publish an event using IBus.Publish
method, the messages do not reach MSMQ. For each published message I only get the following log message.
[DEBUG] 2015-11-20 13:19:43.9444 Message type: 'MyAssembly.Messages.NewEmailEvent' could not be determined by a 'Type.GetType', scanning known messages for a match
The event definition looks like this.
namespace MyAssembly.Messages
{
public class NewEmailEvent
{
public Guid MessageId { get; set; }
public string Subject { get; set; }
public string Sender { get; set; }
// a few other fields
}
}
I am publishing the event using the following code.
m_Bus.Publish<NewEmailEvent>(msg => {
msg.MessageId = entry.MessageId;
msg.Subject = entry.Email.Subject;
msg.Sender = entry.Email.Sender.Name;
// more property assignments
});
I have the following routing configuration.
<MsmqTransportConfig InputQueue="Nsb_input" ErrorQueue="Nsb_errors" NumberOfWorkerThreads="1" MaxRetries="5" />
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Assembly="MyAssembly.Messages" Endpoint="NServiceBus.Service" />
</MessageEndpointMappings>
</UnicastBusConfig>
The event naming conventions are defined in code as follows.
busConfiguration.Conventions().DefiningEventsAs(
t => t.Assembly.GetName().Name.EndsWith(".Messages", StringComparison.InvariantCulture)
&& t.Name.EndsWith("Event", StringComparison.InvariantCulture));
The messages are correctly registered at startup.
[DEBUG] 2015-11-20 13:18:35.1345 Message definitions:
MessageType: MyAssembly.Messages.NewEmailEvent, Recoverable: True, TimeToBeReceived: Not set , Parent types: MyAssembly.Messages.NewEmailEvent
MessageType: NServiceBus.Scheduling.Messages.ScheduledTask, Recoverable: True, TimeToBeReceived: Not set , Parent types: NServiceBus.Scheduling.Messages.ScheduledTask
On the receiving end, I am subscribing to the event using the following code.
bus.Subscribe<NewEmailEvent>();
And using the following configuration.
<UnicastBusConfig>
<MessageEndpointMappings>
<add Assembly="MyAssembly.Messages" Endpoint="NServiceBus.Service" />
</MessageEndpointMappings>
</UnicastBusConfig>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
The event naming conventions are the same as the service.
BusConfiguration.EndpointName
). After changing MessageEndpointMappings at the subscriber side to Nsb_input, I get an error that the queue does not exist. And in fact it does not exist. On the other hand the nservicebus.service queue exists (NServiceBus created it at startup). – Marek Dzikiewicz