NServiceBus无法以不显眼的模式找到Endpoint或MessageEndpointMappings

时间:2015-10-28 15:50:42

标签: c# .net wcf nservicebus nservicebus5

我正在尝试将原始TestService端点连接到原始WCF服务,其中WCF服务实例使用最新的NSB 5.2将原语TestCommand发送到TestService端点。 9 / Host6.0:

[ServiceBehavior(
    InstanceContextMode = InstanceContextMode.PerCall,
    ConcurrencyMode = ConcurrencyMode.Single )]
public class MyService : IMyService
{
    private readonly IBus bus;

    public MyService( IBus bus )
    {
        this.bus = bus;
    }

    public void Test( string value )
    {
        bus.Send( new TestCommand( value ) );
    }
}

我无法正确配置。错误讯息:

Exception thrown: 'System.InvalidOperationException' in System.ServiceModel.dll

Additional information: No destination could be found for message type Company.App.Commands.TestCommand. Check the <**MessageEndpointMappings**> section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.

我可以在不使用&#34;不显眼的节点&#34;的情况下执行此操作,但不能使用约定。在我尝试了一切后,我很困惑如何配置它。 WCF主机是自托管的,而测试端点由NServiceBus.Host托管。

  1. IIS WCF主机应用程序的web.config
  2. via NServiceBus.Config.IConfigurationSource
  3. 通过NServiceBus.Config.IProvideConfiguration
  4. 现在我在web.config中有这个,这看起来毫无用处并且被忽略了:

    <MessageEndpointMappings>
        <add Assembly="Company.App.Messages" Type="Company.App.Commands.TestCommand" Endpoint="testservice" />
    </MessageEndpointMappings>
    

    &#34;不显眼的模式&#34; 我为约定创建了一个单独的项目,由WCF主机端点和TestService端点引用。

    public class MessageConventions : INeedInitialization
    {
        public void Customize( BusConfiguration configuration )
        {
            var conventions = configuration.Conventions();
    
            conventions.DefiningCommandsAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) && t.Namespace.EndsWith( "Commands" ) );
            conventions.DefiningEventsAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) && t.Namespace.EndsWith( "Events" ) );
            conventions.DefiningMessagesAs( t => t.Namespace != null && t.Namespace.StartsWith( "Company.App" ) );
    
            //conventions.DefiningTimeToBeReceivedAs( t => GetTimeToBeReceived( t ) )
            //conventions.DefiningDataBusPropertiesAs( pi => IsDataBusProperty( pi ) );
        }
    }
    

    这些约定似乎由TestService提取。

    我的理解是IIS WCF主机必须在其web.config中声明映射,以便WCF服务知道用bus.Send(new TestCommand("test"));发送消息的位置,但这不起作用。

    然后我尝试在两个端点中定义这些映射,但没有运气。

    此方法将使用上述约定输出找到的所有消息类型:

    public class Startup : IWantToRunWhenBusStartsAndStops
    {
    public MessageMetadataRegistry Messages { get; set; }
    public Conventions Conventions { get; set; }
    
    public void Start()
    {
        var getAllMessagesMethod = typeof( MessageMetadataRegistry ).GetMethod( "GetAllMessages",
            BindingFlags.NonPublic | BindingFlags.Instance );
    
        var allMessages = getAllMessagesMethod.Invoke( Messages, new object[ 0 ] ) as IEnumerable<MessageMetadata>;
    
        foreach ( var metadata in allMessages )
        {
            Type type = metadata.MessageType;
            string name = type.FullName;
    
            if ( this.Conventions.IsInSystemConventionList( type ) )
                Console.WriteLine( "System Msg: {0}", name );
            else if ( this.Conventions.IsCommandType( type ) )
                Console.WriteLine( "   Command: {0}", name );
            else if ( this.Conventions.IsEventType( type ) )
                Console.WriteLine( "     Event: {0}", name );
            else if ( this.Conventions.IsMessageType( type ) )
                Console.WriteLine( "   Message: {0}", name );
    
            if ( metadata.TimeToBeReceived != TimeSpan.MaxValue )
                Console.WriteLine( "            TimeToBeReceived={0}", metadata.TimeToBeReceived );
        }
    }
    
    public void Stop()
    {
    }
    }
    

    上面的方法输出消息类型&#34; TestCommand&#34;,因此它知道所做的约定。

    我已经检查了1000x的错别字,套管,每个人。我清理了解决方案。 我的问题是:为什么NServiceBus无法找到端点?

    请帮忙。

1 个答案:

答案 0 :(得分:1)

Unobtrusive意味着您通过约定告诉NServiceBus哪些类是命令和事件而不是实现标记接口,您仍然需要在app / web配置中添加消息映射,以便NServiceBus知道将消息发送到哪个队列。

异常表明这是你的问题

Check the <**MessageEndpointMappings**> section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.

确保在web.config中仍然有这样的内容:

<UnicastBusConfig>
  <MessageEndpointMappings>
    <add Messages="Company.App.Commands.TestCommand, Company.App.Commands" Endpoint="test.server" />
  </MessageEndpointMappings>
</UnicastBusConfig>

修改

现在您已发布了web.config,问题似乎是web.config中的类型名称错误:

<add Assembly="Company.App.Messages" Type="Company.App.Commands.RunTestCommand"

但你正在做这个bus.Send(new TestCommand(value));

所以web.config错了,应该是

<add Assembly="Company.App.Messages" Type="Company.App.Commands.TestCommand"