Which ServiceControl.Contracts messages should IHandle?

时间:2015-11-12 12:13:33

标签: nservicebus nservicebus5 nsb-servicecontrol

I'm trying to make sure that 3rd party dependencies are running, and built a service to do this based on the Monitoring 3rd party Sample Application, which emits ServiceControl CheckResult messages.

This works fine; ServicePulse alerts me when I stop/start my local and remote windows services, Databases, Flux Capacitors, etc.

I now want to build a windows service / nServiceBus Endpoint, like ServicePulse, but with logic that can attempt recovery, send emails etc. I don't really want to put this code into the 3rdParty monitor.

I followed the servicecontrol/external-integrations and servicecontrol/contracts tutorials, and created my MendStuffOrEmail endpoint - But it doesn't work; It doesn't receive any messages.

I was going to ask "what am I doing wrong?", but I think I know; I'm using IHandleMessages<ServiceControl.Contracts.MessageFailed> which is for failed messages.

I need to listen for the "CheckResult" type messages - but what are they? I have looked through the ServiceControl and ServicePulse code, but cannot work out what is being sent/received. How can I find this out, or has anyone else actually done this and already knows?

UPDATE
After more extensive rummaging, I also subscribed to CustomCheckFailed and CustomCheckSucceeded messages. I implemented IHandle interfaces for them, but I'm still not getting any messages. The log shows autosubscriber has taken out a subscription to them. What should I check for next?

1 个答案:

答案 0 :(得分:0)

我将我的代码与Sean的帖子进行了比较 example并发现错误: 我在错误的类中实现了两个接口 IConfigureThisEndpoint AsA_Server (凌晨2点切换&#39; n&#39;粘贴错误)。

该示例侦听失败的消息,但对于其他任何尝试执行此操作的人,您需要订阅 CustomCheckFailed CustomCheckSucceeded 消息(nuget ServiceControl.Contracts)。

public partial class MessageHandler : IHandleMessages<CustomCheckFailed>,
                                      IHandleMessages<CustomCheckSucceeded>
{
    public void Handle(CustomCheckFailed message)
    {
        this.HandleImplementation(message);
    }
    partial void HandleImplementation(CustomCheckFailed message);

    public void Handle(CustomCheckSucceeded message)
    {
        this.HandleImplementation(message);
    }
    partial void HandleImplementation(CustomCheckSucceeded message);

    public IBus Bus { get; set; }   
}

然后是对消息做某事的逻辑。 (我在原始测试中离开 - 发送电子邮件 - 但我们的系统有一个包含各种恢复和通知方法的库。您需要类似的东西来阻止电子邮件泛滥):

public partial class MessageHandler
{
    partial void HandleImplementation(CustomCheckFailed message)
    {
        var messageBody = string.Format("Message with id {0} failed with reason {1}", message.CustomCheckId, message.FailureReason);
        MailMessageFactory.sendEmail("Failure Notification", messageBody);

        Console.Out.WriteLine(messageBody);
    }
}

带有恢复消息逻辑的类似文件( CustomCheckSucceeded )。您可能希望在那里检查以检测它实际上是从故障中恢复,而不仅仅是通过测试。

无论如何,修复 - 在我的开发电脑上。

接下来的问题是让它在服务器上工作,它接受了支持电话。事实证明,ServiceControl还需要一个许可证,作为&#34; Advanced&#34;,&#34; Enterprise&#34;和&#34; Ultimate&#34;的一部分提供。版本 - 不属于标准许可证平台的一部分。