NServiceBus 警告“找不到消息类型的处理程序" [英] NServiceBus Warning "No handlers could be found for message type"

查看:76
本文介绍了NServiceBus 警告“找不到消息类型的处理程序"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 NServiceBus 的新手,正在尝试开发一个发布者和单独的订阅者(我使用的是 v3.2.0.0),到目前为止,它工作正常——发布者和订阅者都在 NServiceBus 主机中运行.我的消息都发布正常,但间歇性地它们没有被订阅者接收,发布者显示以下错误:

2012-09-05 14:27:37,491 [Worker.6] WARN NServiceBus.Unicast.UnicastBus [(null)] <(null)>- 找不到消息类型的处理程序:MyNamespace.MyMessage

不过,并非所有消息都会出现此警告,因此,如果我在一条消息后继续发布消息,我可能会看到其中一半显示消息,因此订阅者未收到,尽管所有消息都出现在 MSMQ 队列中.

我承认我正在努力解决这个问题,所以到目前为止我的一些代码很可能是完全垃圾!

我按如下方式向 NSB 发布消息,消息输入是我定义的几种不同类型之一:

private void Publish(T 消息){var myBus = Configure.Instance.Builder.Build();myBus.Publish(消息);}

发布者的EndpointConfig如下:

[EndpointName("MyQ​​ueue")]公共类 EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization{///<总结>///NServiceBus 的初始化.///</总结>公共无效初始化(){配置.With().DefaultBuilder().MsmqSubscriptionStorage().DisableTimeoutManager().DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("MyNamespace"));}}

在订阅者方面,我有以下 EndpointConfig:

[EndpointName("MyQ​​ueue")]公共类 EndPointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization{公共无效初始化(){配置.With().DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("MyNamespace"));}}

使用 EventMessageHandler 如下:

public class EventMessageHandler : IEvent, IHandleMessages{公共无效句柄(IMyMessage 消息){Console.WriteLine(string.Format("订阅者 1 收到了 ID 为 {0} 的 EventMessage.", message.Id));}}

订阅者的 app.config 是:

</configSections><MessageForwardingInCaseOfFaultConfig ErrorQueue="错误"/><单播总线配置><MessageEndpointMappings><add Messages="MyNamespace" Endpoint="MyQueue"/></MessageEndpointMappings></UnicastBusConfig></配置>

解决方案

看起来您的发布者和订阅者使用相同的端点名称.NServiceBus 使用端点名称来生成队列名称,这意味着两个进程最终使用相同的队列.

因此,实际上您的发布者正在发布消息,但随后发布者和订阅者正在争夺谁可以处理它们.

当订阅者获胜时,您会看到自己的预期行为.

当发布者获胜时,该消息没有处理程序,因此 NServiceBus 会显示警告.这并不总是一个问题.在某些情况下,您希望接收并简单地忽略一条消息,但此警告至少让您知道它正在发生,在您的情况下,它表示该消息没有被预期的应用程序处理.

所以要修复它,只需更改端点名称.MySubscriber 和 MyPublisher 或类似的东西.

您甚至不需要使用该属性,您只需命名实现 IConfigureThisEndpoint 的类,NServiceBus 将基于该名称构造端点名称.您甚至可以使用下划线,例如 MyProject_MyPublisher : IConfigureThisEndpoint 并且 NServiceBus 会将下划线转换为点,因此您将获得MyProject.MyPublisher"的输入队列,当您有很多时,这对于命名空间非常好端点四处奔波.

I am new to NServiceBus and am trying to develop a publisher and separate subscriber (I’m using v3.2.0.0) which, so far, is sort of working ok – both the publisher and subscriber are running in NServiceBus Host. My messages all publish ok but intermittently they do not get picked up by the subscriber, with the following error being displayed by the publisher:

2012-09-05 14:27:37,491 [Worker.6] WARN  NServiceBus.Unicast.UnicastBus [(null)]  <(null)> - No handlers could be found for message type: MyNamespace.MyMessage

This warning doesn’t appear for all messages though, so if I keep publishing message after message I might see half of them displaying the message and therefore not being picked up by the subscriber, although all are appearing in the MSMQ queue.

I’ll admit I’m struggling to get to grips with this, so some of my code so far may well be complete rubbish!

I am publishing messages to NSB as follows, with the message input being one of several different types I have defined:

private void Publish<T>(T message)
{
    var myBus = Configure.Instance.Builder.Build<IBus>();
    myBus.Publish(message);
}

The EndpointConfig of the publisher is as follows:

[EndpointName("MyQueue")]
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
    /// <summary>
    /// Initialisation for NServiceBus.
    /// </summary>
    public void Init()
    {
        Configure.With()
            .DefaultBuilder()
            .MsmqSubscriptionStorage()
            .DisableTimeoutManager()
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("MyNamespace"));
    }
}

On the subscriber side I have the following EndpointConfig:

[EndpointName("MyQueue")]
public class EndPointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
    public void Init()
    {
        Configure.With()
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("MyNamespace"));
    }
}

With an EventMessageHandler as follows:

public class EventMessageHandler : IEvent, IHandleMessages<IMyMessage>
{
    public void Handle(IMyMessage message)
    {
        Console.WriteLine(string.Format("Subscriber 1 received EventMessage with Id {0}.", message.Id));
    }
}

The subscriber’s app.config is:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
  </configSections>

  <MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MyNamespace" Endpoint="MyQueue" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
</configuration>

解决方案

It looks like you are using the same endpoint name for both your publisher and your subscriber. NServiceBus uses the endpoint name to generate the queue names, so that means that both processes wind up using the same queue.

So in effect your publisher is publishing messages, but then the publisher and the subscriber are fighting over who gets to process them.

When the subscriber wins, you see your intended behavior.

When the publisher wins, there is no handler for that message, so NServiceBus displays a warning. This isn't always a problem; there are certain scenarios where you would want to receive and simply ignore a message, but this warning allows you to at least know it's happening, and in your case, it's saying that the message isn't being processed by the intended application.

So to fix it, simply change the endpoint names. MySubscriber and MyPublisher, or something like that.

You don't even need to use that attribute, you can just name the class that implements IConfigureThisEndpoint and NServiceBus will construct the endpoint name based on that. You can even use underscores such as MyProject_MyPublisher : IConfigureThisEndpoint and NServiceBus will turn the underscores into dots, so you'll get an input queue of "MyProject.MyPublisher" which is really nice for namespacing when you have many endpoints running around.

这篇关于NServiceBus 警告“找不到消息类型的处理程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆