NServiceBus仅发送端点不生成心跳

时间:2018-02-22 11:43:14

标签: nservicebus nservicebus6

我正在使用NServiceBus.Core v6.4.3NServiceBus.Heartbeat v2.0.0

我有一个作为计划任务运行的控制台应用程序,它提取数据并将命令发送到端点进行处理。

控制台应用程序配置为SendOnly端点。

我的代码如下:

主要

// Local NServiceBus Configuration
var endpointConfiguration = EndpointConfiguration();
// Global NServiceBus & Ninject configuration
var conventions = new NServiceBusConventions();
conventions.Customize(endpointConfiguration);
// Create and start endpoint
var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

EndpointConfiguration

private static EndpointConfiguration EndpointConfiguration()
{
    var configuration = new EndpointConfiguration("EndpointName");

    // To ensure OctopusDeploy doesn't cause ServicePulse to think multiple services have been deployed
    // http://docs.particular.net/nservicebus/hosting/override-hostid
    configuration.UniquelyIdentifyRunningInstance()
        .UsingNames("EndpointName", Environment.MachineName);

    configuration.SendOnly();

    return configuration;         
}

会展

public class NServiceBusConventions
{
    public IKernel Kernel;

    public void Customize(EndpointConfiguration configuration)
    {
        // Custom Logging Factory implementation
        LogManager.UseFactory(new NServiceBusTraceLoggerFactory());

        Kernel = NinjectCommon.Start();

        configuration.UseContainer<NinjectBuilder>(b => b.ExistingKernel(Kernel));
        configuration.UsePersistence<NHibernatePersistence>();
        configuration.UseSerialization<JsonSerializer>();
        configuration.UseTransport<MsmqTransport>();
        var transport = configuration.UseTransport<MsmqTransport>();
        // Enabled by default in MsmqTransport, but to ensure we have it
        transport.Transactions(TransportTransactionMode.TransactionScope);

        configuration.DefineCriticalErrorAction(NServiceBusOnCriticalError.OnCriticalError);    

        configuration.EnableInstallers();
        configuration.Conventions()
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.Equals("Contracts.Commands"))
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.Equals("Contracts.Interfaces.Events"));

        configuration.AuditProcessedMessagesTo(ConfigurationManager.AppSettings["Messaging.NServiceBus.QueueNames.AuditQueue"]);
        configuration.SendFailedMessagesTo(ConfigurationManager.AppSettings["Messaging.NServiceBus.QueueNames.ErrorQueue"]);
        configuration.SendHeartbeatTo(ConfigurationManager.AppSettings["Messaging.NServiceBus.QueueNames.ServiceControlQueue"]);

        var scanner = configuration.AssemblyScanner();

        var excludeRegexs = new List<string>
        {
            @"DevExpress.*\.dll"
        };

        var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
        foreach (var fileName in Directory.EnumerateFiles(baseDirectory, "*.dll").Select(Path.GetFileName))
        {
            foreach (var pattern in excludeRegexs)
            {
                if (Regex.IsMatch(fileName, pattern, RegexOptions.IgnoreCase))
                {
                    scanner.ExcludeAssemblies(fileName);
                    break;
                }
            }
        }
    }
}

删除configuration.SendOnly();中的EndpointConfiguration行会使端点显示在ServicePulse中,但它不会出现。

我知道这是以前版本中的问题,但我认为这已在NServiceBus V5修复。

我不必将端点配置为仅发送,但我只是为了完整性。

1 个答案:

答案 0 :(得分:0)

缺少心跳的原因是:

  

我有一个控制台应用程序,它以计划任务运行,它提取   数据并将命令发送到端点进行处理。

每次都会重新启动该过程,并且提取数据,处理和发送命令所花费的时间对于NServiceBus而言太短,无法发送心跳消息。

在应用程序的末尾放置await Task.Delay(10000)足以使NServiceBus完成其必要的引导,并且不会影响我们的SLA。

感谢肖恩·法玛(Sean Farmar)的诊断帮助