我正在使用NServiceBus.Core v6.4.3
和NServiceBus.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);
端点配置
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
.
我不必将端点配置为仅发送,但我只是为了完整性。