【问题标题】:NServiceBus cannot find Endpoint or MessageEndpointMappings in unobtrusive modeNServiceBus 在不显眼的模式下找不到 Endpoint 或 MessageEndpointMappings
【发布时间】:2015-10-28 15:50:41
【问题描述】:

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

[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.

我可以在不使用“不显眼的节点”的情况下做到这一点,但不能使用约定。在我尝试了一切之后,我对如何配置它感到非常困惑。 WCF 主机是自托管的,而测试端点由 NServiceBus.Host 托管。

  1. IIS WCF 主机应用程序的 web.config
  2. 通过 NServiceBus.Config.IConfigurationSource
  3. 通过 NServiceBus.Config.IProvideConfiguration

现在我在 web.config 中有这个,它看起来毫无用处并且被忽略了:

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

“Unobtrusive mode”:我为约定创建了一个单独的项目,由 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()
{
}
}

上述方法输出消息类型“TestCommand”,因此它知道所做的约定。

我已经检查了 1000 倍的拼写错误、大小写和所有内容。我清洗了溶液。 我的问题是:为什么 NServiceBus 找不到端点?

请帮忙。

【问题讨论】:

  • 你能从 web.config 发布你的映射吗?
  • @TylerDay 谢谢,我更新了我的问题。要记住的是,我尝试使用 IConfigurationSource 和 IProvideConfiguration 使用 web.config 和 WTIHOUT 进行配置。这些都不起作用。谢谢!
  • 您的 webconfig 映射了一个名为“RunTestCommand”的命令,而不是示例代码所示的“TestCommand”。
  • @TylerDay 不是这样。只是一个类型,同时匿名上面的代码。道歉。

标签: c# .net wcf nservicebus nservicebus5


【解决方案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"

【讨论】:

  • 谢谢,但我在 web.config 中有所有这些。我认为您使用的配置属性不正确:Messages="...",这不应该是 Assembly="..." 吗?
  • 它可能略有变化,我还没有使用 NSB 5。
  • 你说得对,Messages 仍然可以使用,Assembly 也可以使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多