Exemplo n.º 1
0
        public IBusControl CreateBus(IBusServiceConfigurator busServiceConfigurator, string serviceName)
        {
            serviceName = serviceName.ToLowerInvariant().Trim().Replace(" ", "_");

            var hostSettings = new SettingsAdapter(_settings, serviceName);

            if (hostSettings.ServiceUri == null)
            {
                throw new ConfigurationException("The ServiceBus ServiceUri setting has not been configured");
            }

            return(AzureBusFactory.CreateUsingServiceBus(configurator =>
            {
                var host = configurator.Host(hostSettings.ServiceUri, h =>
                {
                    h.SharedAccessSignature(s =>
                    {
                        s.KeyName = hostSettings.KeyName;
                        s.SharedAccessKey = hostSettings.SharedAccessKey;
                        s.TokenTimeToLive = hostSettings.TokenTimeToLive;
                        s.TokenScope = hostSettings.TokenScope;
                    });
                });

                if (_log.IsInfoEnabled)
                {
                    _log.Info($"Configuring Host: {hostSettings.ServiceUri}");
                }

                var serviceConfigurator = new ServiceBusServiceConfigurator(configurator, host);

                busServiceConfigurator.Configure(serviceConfigurator);
            }));
        }
        public IBusControl CreateBus(IBusServiceConfigurator busServiceConfigurator, string serviceName)
        {
            if (string.IsNullOrEmpty(_hostSettings.Namespace))
            {
                throw new ConfigurationException("The ServiceBus Namespace setting has not been configured");
            }

            if (string.IsNullOrEmpty(_hostSettings.KeyName))
            {
                throw new ConfigurationException("The ServiceBus KeyName setting has not been configured");
            }

            if (string.IsNullOrEmpty(_hostSettings.SharedAccessKey))
            {
                throw new ConfigurationException("The ServiceBus SharedAccessKey setting has not been configured");
            }

            return(AzureBusFactory.CreateUsingServiceBus(configurator =>
            {
                serviceName = serviceName.ToLowerInvariant().Trim().Replace(" ", "_");
                _hostSettings.ServiceUri = ServiceBusEnvironment.CreateServiceUri("sb",
                                                                                  _hostSettings.Namespace, serviceName);

                var host = configurator.Host(_hostSettings.ServiceUri, h =>
                {
                    h.SharedAccessSignature(s =>
                    {
                        s.KeyName = _hostSettings.KeyName;
                        s.SharedAccessKey = _hostSettings.SharedAccessKey;
                        s.TokenTimeToLive = _hostSettings.TokenTimeToLive;
                        s.TokenScope = _hostSettings.TokenScope;
                    });
                });

                if (_log.IsInfoEnabled)
                {
                    _log.Info($"Configuring Host: { _hostSettings.ServiceUri}");
                }

                var serviceConfigurator = new ServiceBusServiceConfigurator(configurator, host);

                busServiceConfigurator.Configure(serviceConfigurator);
            }));
        }
Exemplo n.º 3
0
        public IBusControl CreateBus(IBusServiceConfigurator busServiceConfigurator, string serviceName)
        {
            serviceName = serviceName.ToLowerInvariant().Trim().Replace(" ", "_");

            var hostSettings = new SettingsAdapter(_settings, _ampAmqpTransportSettings, _netMessagingTransportSettings, serviceName);

            if (hostSettings.ServiceUri == null)
            {
                throw new ConfigurationException("The ServiceBus ServiceUri setting has not been configured");
            }

            return(AzureBusFactory.CreateUsingServiceBus(configurator =>
            {
                var host = configurator.Host(hostSettings.ServiceUri, h =>
                {
                    if (!string.IsNullOrWhiteSpace(hostSettings.ConnectionString))
                    {
                        h.TokenProvider = hostSettings.TokenProvider;
                    }
                    else
                    {
                        h.SharedAccessSignature(s =>
                        {
                            s.KeyName = hostSettings.KeyName;
                            s.SharedAccessKey = hostSettings.SharedAccessKey;
                            s.TokenTimeToLive = hostSettings.TokenTimeToLive;
                            s.TokenScope = hostSettings.TokenScope;
                        });
                    }
                });

                LogContext.Info?.Log("Configuring Host: {Host}", hostSettings.ServiceUri);

                var serviceConfigurator = new ServiceBusServiceConfigurator(configurator);

                busServiceConfigurator.Configure(serviceConfigurator);
            }));
        }