Beispiel #1
0
    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)
        });
    }
        public static string ToTransportAddress(this ReadOnlySettings settings, string queueName)
        {
            var transportInfrastructure = settings.Get <TransportInfrastructure>();
            var logicalAddress          = LogicalAddress.CreateLocalAddress(queueName, null);

            return(transportInfrastructure.ToTransportAddress(logicalAddress));
        }
Beispiel #3
0
        /// <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));
        }
        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);
        }
Beispiel #5
0
    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)
        });
    }
        void InitializeIfNecessary()
        {
            if (Interlocked.Exchange(ref initializeSignaled, 1) != 0)
            {
                return;
            }

            Guard.AgainstUnsetSerializerSetting(Settings);

            var sendOnly = Settings.GetOrDefault <bool>("Endpoint.SendOnly");
            var localAddressForSendOnlyEndpoint = ToTransportAddress(LogicalAddress.CreateLocalAddress(Settings.EndpointName(), new Dictionary <string, string>()));

            try
            {
                localAddress = sendOnly ? localAddressForSendOnlyEndpoint : Settings.LocalAddress();
            }
            catch
            {
                // For tests other than Acceptance tests, LocalAddress() will throw
                localAddress = localAddressForSendOnlyEndpoint;
            }

            defaultNamespaceAlias        = Settings.Get <string>(WellKnownConfigurationKeys.Topology.Addressing.DefaultNamespaceAlias);
            namespaceConfigurations      = Settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces);
            messageSizePaddingPercentage = Settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MessageSizePaddingPercentage);

            var partitioningStrategyType = (Type)Settings.Get(WellKnownConfigurationKeys.Topology.Addressing.Partitioning.Strategy);

            partitioningStrategy = partitioningStrategyType.CreateInstance <INamespacePartitioningStrategy>(Settings);

            namespaceManager = new NamespaceManagerLifeCycleManagerInternal(new NamespaceManagerCreator(Settings));
            messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(new MessagingFactoryCreator(namespaceManager, Settings), Settings);

            messageReceiverLifeCycleManager = new MessageReceiverLifeCycleManager(new MessageReceiverCreator(messagingFactoryLifeCycleManager, Settings), Settings);
            senderLifeCycleManager          = new MessageSenderLifeCycleManager(new MessageSenderCreator(messagingFactoryLifeCycleManager, Settings), Settings);

            oversizedMessageHandler = (IHandleOversizedBrokeredMessages)Settings.Get(WellKnownConfigurationKeys.Connectivity.MessageSenders.OversizedBrokeredMessageHandlerInstance);

            topologyManager  = CreateTopologySectionManager(defaultNamespaceAlias, namespaceConfigurations, partitioningStrategy, addressingLogic);
            topologyCreator  = new TopologyCreator(CreateSubscriptionCreator(), new AzureServiceBusQueueCreator(TopologySettings.QueueSettings, Settings), new AzureServiceBusTopicCreator(TopologySettings.TopicSettings), namespaceManager, Settings);
            topologyOperator = new TopologyOperator(messageReceiverLifeCycleManager, new BrokeredMessagesToIncomingMessagesConverter(Settings, new DefaultConnectionStringToNamespaceAliasMapper(Settings)), Settings);
        }