1
votes

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.

1
Can you show what you're subscribing code looks like?Udi Dahan
I updated my question with the source code and configuration of the subscribing application.Marek Dzikiewicz
And what is at the "NServiceBus.Service" endpoint? Shooting from the hip, I'd say you need to change your MessageEndpointMappings at the subscriber side to point to Nsb_input instead.Udi Dahan
Did you resolve your issue? Is the message convention applied on both the publisher and the subscriber and are they identical?Ramon Smits
"NServiceBus.Service" is the endpoint of the application which sends the events (the endpoint name is set using 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

1 Answers

0
votes

Your MessageEndpointMappings are the same for both publisher and subscriber - don't know if this is correct / makes a difference.

You have not defined any message or command conventions; only events.

busConfiguration.Conventions()
    .DefiningMessagesAs(t => t.Namespace != null &&
                         t.Namespace.StartsWith("MyAssembly.Messages"))
    .DefiningCommandsAs(t => t.Namespace != null &&
                         t.Namespace.StartsWith("MyAssembly.Commands"))

I think you need to do this if you're not using marker interfaces.

I think this is especially important within the subscriber.

You haven't included the code for your subscriber. Does it have a class that implements IHandleMessages<NewEmailEvent>?

Go back and look at the pub/sub example.

Check your config settings again. It doesn't look like you're using external files; the sections are directly in app.config