public override string ToTransportAddress(LogicalAddress logicalAddress) { var address = logicalAddress.EndpointInstance.Endpoint; PathChecker.ThrowForBadPath(address, "endpoint name"); var discriminator = logicalAddress.EndpointInstance.Discriminator; if (!string.IsNullOrEmpty(discriminator)) { PathChecker.ThrowForBadPath(discriminator, "endpoint discriminator"); address += "-" + discriminator; } var qualifier = logicalAddress.Qualifier; if (!string.IsNullOrEmpty(qualifier)) { PathChecker.ThrowForBadPath(qualifier, "address qualifier"); address += "-" + qualifier; } return(address); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var endpointInstance = logicalAddress.EndpointInstance; var discriminator = endpointInstance.Discriminator ?? ""; var qualifier = logicalAddress.Qualifier ?? ""; return Path.Combine(endpointInstance.Endpoint, discriminator, qualifier); }
public Forwarder(HashSet <string> knownPartitionKeys, Func <LogicalAddress, string> addressTranslator, LogicalAddress logicalAddress) { this.knownPartitionKeys = knownPartitionKeys; this.addressTranslator = addressTranslator; this.logicalAddress = logicalAddress; }
/// <inheritdoc cref="Command.ReportPhysicalAddress"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="deviceType">Type of the device.</param> /// <param name="physicalAddress">The physical address.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> public static CecMessage ReportPhysicalAddress(LogicalAddress source, DeviceType deviceType, PhysicalAddress physicalAddress) { var args = ByteArrayHelper.ToByteArray(physicalAddress.Address) .Concat(ByteArrayHelper.ToByteArray(deviceType)).ToArray(); return(new CecMessage(source, LogicalAddress.Unregistered, Command.ReportPhysicalAddress, args)); }
/// <inheritdoc cref="Command.FeatureAbort"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="destination">The <c>CecMessage</c> destination.</param> /// <param name="opCode">The <c>Command</c> which is aborted.</param> /// <param name="reason">A <c>AbortReason</c> value.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> public static CecMessage FeatureAbort(LogicalAddress source, LogicalAddress destination, Command opCode, AbortReason reason) { var args = ByteArrayHelper.ToByteArray(opCode) .Concat(ByteArrayHelper.ToByteArray(reason)).ToArray(); return(new CecMessage(source, destination, Command.FeatureAbort, args)); }
public DistributeSubscriptions(string localPartitionKey, HashSet <string> knownPartitionKeys, Func <LogicalAddress, string> addressTranslator, LogicalAddress logicalAddress) { this.logicalAddress = logicalAddress; this.addressTranslator = addressTranslator; this.localPartitionKey = localPartitionKey; this.knownPartitionKeys = knownPartitionKeys; }
public static string ToTransportAddress(this ReadOnlySettings settings, string queueName) { var transportInfrastructure = settings.Get <TransportInfrastructure>(); var logicalAddress = LogicalAddress.CreateLocalAddress(queueName, null); return(transportInfrastructure.ToTransportAddress(logicalAddress)); }
/// <inheritdoc cref="Command.RoutingChange"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="originalAddress">The original physical address.</param> /// <param name="newAddress">The new physical address.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> public static CecMessage RoutingChange(LogicalAddress source, PhysicalAddress originalAddress, PhysicalAddress newAddress) { var parameters = ByteArrayHelper.ToByteArray(originalAddress.Address) .Concat(ByteArrayHelper.ToByteArray(newAddress.Address)).ToArray(); return(new CecMessage(source, LogicalAddress.Unregistered, Command.RoutingChange, parameters)); }
public TransportConfigurationResult Configure(SettingsHolder settings, TransportTransactionMode transportTransactionMode) { #if !NETFRAMEWORK if (transportTransactionMode == TransportTransactionMode.TransactionScope) { NUnit.Framework.Assert.Ignore("TransactionScope not supported in .NET Core"); } #endif this.settings = settings; settings.Set(transportTransactionMode); settings.Set("NServiceBus.SharedQueue", settings.EndpointName()); var delayedDeliverySettings = new DelayedDeliverySettings(settings); delayedDeliverySettings.TableSuffix("Delayed"); var pubSubSettings = new SubscriptionSettings(); pubSubSettings.DisableSubscriptionCache(); settings.Set(pubSubSettings); connectionString = Environment.GetEnvironmentVariable("SqlServerTransportConnectionString"); if (string.IsNullOrEmpty(connectionString)) { connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Integrated Security=True"; } var logicalAddress = LogicalAddress.CreateLocalAddress(settings.ErrorQueueAddress(), new Dictionary <string, string>()); var localAddress = settings.EndpointName(); return(new TransportConfigurationResult { TransportInfrastructure = new SqlServerTransportInfrastructure("nservicebus", settings, connectionString, () => localAddress, () => logicalAddress, false) }); }
/// <summary> /// Initializes a new instance of the <see cref="CecMessage"/> struct. /// </summary> /// <param name="source">The source address.</param> /// <param name="destination">The destination address.</param> /// <param name="command">The message command.</param> /// <param name="isAcknowledged">if set to <c>true</c> [is acknowledged].</param> /// <param name="parameters">The message parameters.</param> public CecMessage(LogicalAddress source, LogicalAddress destination, Command command, bool isAcknowledged, byte[] parameters) { Source = source; Destination = destination; Command = command; Parameters = parameters; this.isAcknowledged = isAcknowledged; }
/// <summary> /// This method is copied from the core because there is no other way to reliable get the address of the main input queue. /// </summary> /// <returns></returns> LogicalAddress GetLogicalAddress() { var queueNameBase = settings.GetOrDefault <string>("BaseInputQueueName") ?? settings.EndpointName(); //note: This is an old hack, we are passing the endpoint name to bind but we only care about the properties var mainInstanceProperties = BindToLocalEndpoint(new EndpointInstance(settings.EndpointName())).Properties; return(LogicalAddress.CreateLocalAddress(queueNameBase, mainInstanceProperties)); }
/// <inheritdoc cref="Command.VendorRemoteButtonDown"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="destination">The <c>CecMessage</c> destination.</param> /// <param name="data">The data.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> /// <exception cref="ArgumentException"></exception> public static CecMessage VendorRemoteButtonDown(LogicalAddress source, LogicalAddress destination, byte[] data) { if (data.Length > 14 || data.Length == 0) { throw new ArgumentException("Data must be between 1 and 14 bytes", nameof(data)); } return(new CecMessage(source, destination, Command.VendorRemoteButtonDown, data)); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { if (!logicalAddress.EndpointInstance.Properties.TryGetValue("queue", out var queue)) { queue = "receiving"; } return($"{queue}@{logicalAddress.EndpointInstance.Endpoint}"); }
public Register(string localPartitionKey, HashSet <string> knownPartitionKeys, Func <LogicalAddress, string> addressTranslator, LogicalAddress logicalAddress) : base("DistributeSubscriptions", typeof(DistributeSubscriptions), "Distributes subscription messages for message driven pubsub using header only.", b => new DistributeSubscriptions(localPartitionKey, knownPartitionKeys, addressTranslator, logicalAddress)) { InsertBeforeIfExists("ProcessSubscriptionRequests"); }
private static DefaultEventDistributor GetEventDistributor(FeatureConfigurationContext context) { var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var distributionPolicy = context.Settings.Get <DistributionPolicy>(); var eventDistributor = new DefaultEventDistributor( distributionPolicy, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); return(eventDistributor); }
/// <inheritdoc cref="Command.ReportAudioStatus"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="destination">The <c>CecMessage</c> destination.</param> /// <param name="status">The status.</param> /// <param name="value">The value.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> /// <exception cref="System.ArgumentException">Value must be between 0 and 127 (inclusive). - value</exception> public static CecMessage ReportAudioStatus(LogicalAddress source, LogicalAddress destination, AudioMuteStatus status, int value) { if (!value.InRange(0, 127)) { throw new ArgumentException("Value must be between 0 and 127 (inclusive).", nameof(value)); } var args = Convert.ToByte(status) | Convert.ToByte(value); return(new CecMessage(source, destination, Command.ReportAudioStatus, ByteArrayHelper.ToByteArray(args, "X2"))); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var topic = new StringBuilder(logicalAddress.EndpointInstance.Endpoint); if (logicalAddress.Qualifier != null) { topic.Append("." + logicalAddress.Qualifier); } return(topic.ToString()); }
public async Task <IStartableRawEndpoint> Initialize() { CreateCriticalErrorHandler(); CreateStartupDiagnostics(); var transportDefinition = settings.Get <TransportDefinition>(); var connectionString = settings.GetConnectionString(); var transportInfrastructure = transportDefinition.Initialize(settings, connectionString); settings.Set(transportInfrastructure); var mainInstance = transportInfrastructure.BindToLocalEndpoint(new EndpointInstance(settings.EndpointName())); var baseQueueName = settings.GetOrDefault <string>("BaseInputQueueName") ?? settings.EndpointName(); var mainLogicalAddress = LogicalAddress.CreateLocalAddress(baseQueueName, mainInstance.Properties); var localAddress = transportInfrastructure.ToTransportAddress(mainLogicalAddress); settings.SetDefault(mainLogicalAddress); IPushMessages messagePump = null; IManageSubscriptions subscriptionManager = null; if (!settings.GetOrDefault <bool>("Endpoint.SendOnly")) { RegisterReceivingComponent(settings, mainLogicalAddress, localAddress); var receiveInfrastructure = transportInfrastructure.ConfigureReceiveInfrastructure(); var queueCreator = receiveInfrastructure.QueueCreatorFactory(); messagePump = receiveInfrastructure.MessagePumpFactory(); var queueBindings = settings.Get <QueueBindings>(); queueBindings.BindReceiving(localAddress); if (settings.GetOrDefault <bool>("NServiceBus.Raw.CreateQueue")) { await queueCreator.CreateQueueIfNecessary(queueBindings, GetInstallationUserName()).ConfigureAwait(false); } if (transportInfrastructure.OutboundRoutingPolicy.Publishes == OutboundRoutingType.Multicast || transportInfrastructure.OutboundRoutingPolicy.Sends == OutboundRoutingType.Multicast) { subscriptionManager = CreateSubscriptionManager(transportInfrastructure); } } var sendInfrastructure = transportInfrastructure.ConfigureSendInfrastructure(); var dispatcher = sendInfrastructure.DispatcherFactory(); await transportInfrastructure.Start().ConfigureAwait(false); var startableEndpoint = new StartableRawEndpoint(settings, transportInfrastructure, CreateCriticalErrorHandler(), messagePump, dispatcher, subscriptionManager, onMessage, localAddress); return(startableEndpoint); }
/// <inheritdoc cref="Command.VendorCommandWithId"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="destination">The <c>CecMessage</c> destination.</param> /// <param name="vendorId">The Vendor Id.</param> /// <param name="data">The data.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> /// <exception cref="ArgumentException"></exception> public static CecMessage VendorCommandWithId(LogicalAddress source, LogicalAddress destination, int vendorId, byte[] data) { if (data.Length > 14 || data.Length == 0) { throw new ArgumentException("Data must be between 1 and 14 bytes", nameof(data)); } var parameters = ByteArrayHelper.ToByteArray(vendorId, "X6") .Concat(data).ToArray(); return(new CecMessage(source, destination, Command.VendorCommandWithId, parameters)); }
/// <summary> /// Initializes a new instance of the <see cref="CecDevice"/> class. /// </summary> /// <param name="deviceType">Type of the device.</param> /// <param name="osdName">The OSD name of the device.</param> /// <param name="vendorId">The vendor identifier.</param> /// <param name="physicalAddress">The physical address.</param> /// <param name="logicalAddress">The logical address.</param> /// <exception cref="ArgumentException"></exception> public CecDevice(DeviceType deviceType, string osdName, int vendorId, PhysicalAddress physicalAddress, LogicalAddress logicalAddress) { if (string.IsNullOrEmpty(osdName) || osdName.Length > 14) { throw new ArgumentException("OSD name may not be empty or exceed 14 characters", nameof(osdName)); } DeviceType = deviceType; OsdName = osdName; VendorId = vendorId; PhysicalAddress = physicalAddress; LogicalAddress = logicalAddress; }
public TransportConfigurationResult Configure(SettingsHolder settings, TransportTransactionMode transportTransactionMode) { this.settings = settings; settings.Set("NServiceBus.SharedQueue", settings.EndpointName()); settings.Set <LogicalAddress>(LogicalAddress.CreateLocalAddress(settings.EndpointName(), new Dictionary <string, string>())); var delayedDeliverySettings = new DelayedDeliverySettings(); delayedDeliverySettings.TableSuffix("Delayed"); settings.Set <DelayedDeliverySettings>(delayedDeliverySettings); return(new TransportConfigurationResult { TransportInfrastructure = new SqlServerTransport().Initialize(settings, ConnectionString) }); }
/// <inheritdoc cref="Command.SetMenuLanguage"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="language">The ISO-639-2 language code.</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> /// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentNullException"></exception> public static CecMessage SetMenuLanguage(LogicalAddress source, [NotNull] string language) { if (string.IsNullOrEmpty(language)) { throw new ArgumentNullException(nameof(language)); } if (!IsValidLanguageCode(language)) { throw new ArgumentException("The language code is invalid", nameof(language)); } return(new CecMessage(source, LogicalAddress.Unregistered, Command.SetMenuLanguage, ByteArrayHelper.ToByteArray(language))); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var queue = new StringBuilder(logicalAddress.EndpointInstance.Endpoint); if (logicalAddress.EndpointInstance.Discriminator != null) { queue.Append("-" + logicalAddress.EndpointInstance.Discriminator); } if (logicalAddress.Qualifier != null) { queue.Append("." + logicalAddress.Qualifier); } return(queue.ToString()); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var queue = new StringBuilder(logicalAddress.EndpointInstance.Endpoint); if (logicalAddress.EndpointInstance.Discriminator != null) { queue.Append($"-{logicalAddress.EndpointInstance.Discriminator}"); } if (logicalAddress.Qualifier != null) { queue.Append($".{logicalAddress.Qualifier}"); } return(addressingLogic.Apply(queue.ToString(), EntityType.Queue).ToString()); }
static QueueAddress TranslateLogicalAddress(LogicalAddress logicalAddress) { var nonEmptyParts = new[] { logicalAddress.EndpointInstance.Endpoint, logicalAddress.Qualifier, logicalAddress.EndpointInstance.Discriminator }.Where(p => !string.IsNullOrEmpty(p)); var tableName = string.Join(".", nonEmptyParts); logicalAddress.EndpointInstance.Properties.TryGetValue(SettingsKeys.SchemaPropertyKey, out var schemaName); logicalAddress.EndpointInstance.Properties.TryGetValue(SettingsKeys.CatalogPropertyKey, out var catalogName); return(new QueueAddress(tableName, schemaName, catalogName)); }
/// <inheritdoc cref="Command.SetOSDString"/> /// <param name="source">The <c>CecMessage</c> source.</param> /// <param name="destination">The <c>CecMessage</c> destination.</param> /// <param name="displayControl">The display control value.</param> /// <param name="osdString">The osd string to display (max. 13 characters).</param> /// <returns>A <c>CecMessage</c> that represents the command.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static CecMessage SetOSDString(LogicalAddress source, DisplayControl displayControl, [NotNull] string osdString) { if (string.IsNullOrEmpty(osdString)) { throw new ArgumentNullException(nameof(osdString)); } if (osdString.Length > 13) { throw new ArgumentException("The string length may not exceed 13 characters.", nameof(osdString)); } var parameters = ByteArrayHelper.ToByteArray(displayControl) .Concat(ByteArrayHelper.ToByteArray(osdString)).ToArray(); return(new CecMessage(source, LogicalAddress.TV, Command.SetOSDString, parameters)); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var nonEmptyParts = new[] { logicalAddress.EndpointInstance.Endpoint, logicalAddress.Qualifier, logicalAddress.EndpointInstance.Discriminator }.Where(p => !string.IsNullOrEmpty(p)); var tableName = string.Join(".", nonEmptyParts); string schemaName; logicalAddress.EndpointInstance.Properties.TryGetValue(SettingsKeys.SchemaPropertyKey, out schemaName); var queueAddress = new QueueAddress(tableName, schemaName); return(queueAddress.ToString()); }
public void Setup(FeatureConfigurationContext context) { var mainEndpointName = context.Settings.EndpointName(); var routerEndpointName = $"{mainEndpointName}_Migrator"; var settings = context.Settings.Get <MigratorSettings>(); var unicastRouteTable = context.Settings.Get <UnicastRoutingTable>(); var distributionPolicy = context.Settings.Get <DistributionPolicy>(); var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var queueBindings = context.Settings.Get <QueueBindings>(); var customizeOldTransport = context.Settings.Get <Action <TransportExtensions <TOld> > >(MigratorConfigurationExtensions.OldTransportCustomizationSettingsKey); var customizeNewTransport = context.Settings.Get <Action <TransportExtensions <TNew> > >(MigratorConfigurationExtensions.NewTransportCustomizationSettingsKey); var routerAddress = transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(new EndpointInstance(routerEndpointName))); queueBindings.BindSending(routerAddress); //context.RegisterStartupTask(b => new RoutingMonitor(unicastRouteTable, settings.SendRouteTable, route, b.Build<CriticalError>())); var route = UnicastRoute.CreateFromPhysicalAddress(routerAddress); var routes = settings.SendRouteTable.Select(x => new RouteTableEntry(x.Key, route)).ToList(); unicastRouteTable.AddOrReplaceRoutes("NServiceBus.Router.Migrator", routes); context.Pipeline.Register(new MigratorRouterDestinationBehavior(settings.SendRouteTable), "Sets the ultimate destination endpoint on the outgoing messages."); context.Pipeline.Replace("MigrationModePublishConnector", b => new DualRoutingPublishConnector(routerAddress, distributionPolicy, b.Build <MessageMetadataRegistry>(), i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)), b.Build <ISubscriptionStorage>()), "Routes published messages via router and publishes them natively"); context.Pipeline.Register(b => new UnsubscribeAfterMigrationBehavior(b.BuildAll <ISubscriptionStorage>().FirstOrDefault()), "Removes old transport subscriptions when a new transport subscription for the same event and endpoint comes in"); context.Pipeline.Register(new DualRoutingFilterBehavior(mainEndpointName), "Ignores duplicates when publishing both natively and message-driven"); context.Pipeline.Register(b => new MigratorRouterSubscribeBehavior(context.Settings.LocalAddress(), context.Settings.EndpointName(), routerAddress, b.Build <IDispatchMessages>(), settings.PublisherTable), "Dispatches the subscribe request via a router."); var routerConfig = PrepareRouterConfiguration(routerEndpointName, mainEndpointName, context.Settings.LocalAddress(), customizeOldTransport, customizeNewTransport); context.RegisterStartupTask(new MigratorStartupTask(routerConfig)); }
static void RegisterReceivingComponent(SettingsHolder settings, LogicalAddress logicalAddress, string localAddress) { const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance; var parameters = new[] { typeof(LogicalAddress), typeof(string), typeof(string), typeof(string), typeof(TransportTransactionMode), typeof(PushRuntimeSettings), typeof(bool) }; var ctor = typeof(Endpoint).Assembly.GetType("NServiceBus.ReceiveConfiguration", true).GetConstructor(flags, null, parameters, null); var receiveConfig = ctor.Invoke(new object[] { logicalAddress, localAddress, localAddress, null, null, null, false }); settings.Set("NServiceBus.ReceiveConfiguration", receiveConfig); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { var endpointInstance = logicalAddress.EndpointInstance; var discriminator = endpointInstance.Discriminator ?? ""; var qualifier = logicalAddress.Qualifier ?? ""; var transportAddress = endpointInstance.ToString(); if (!string.IsNullOrEmpty(discriminator)) { transportAddress += "/" + discriminator; } if (!string.IsNullOrEmpty(qualifier)) { transportAddress += "/" + qualifier; } return(transportAddress); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { return logicalAddress.ToString(); }
public override string ToTransportAddress(LogicalAddress logicalAddress) { throw new NotImplementedException(); }
/// <summary> /// Gets the native transport address for the given logical address. /// </summary> /// <returns>The native transport address.</returns> public static string GetTransportAddress(this ReadOnlySettings settings, LogicalAddress logicalAddress) { return settings.Get<TransportInfrastructure>().ToTransportAddress(logicalAddress); }
/// <summary> /// Converts a given logical address to the transport address. /// </summary> /// <param name="logicalAddress">The logical address.</param> /// <returns>The transport address.</returns> public abstract string ToTransportAddress(LogicalAddress logicalAddress);