Ejemplo n.º 1
0
        private static IBusControl BusControl()
        {
            var bus = Bus.Factory.CreateUsingAzureServiceBus(sbc =>
            {
                var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb",
                                                                        ConfigurationManager.AppSettings["AzureSbNamespace"],
                                                                        ConfigurationManager.AppSettings["AzureSbPath"]);

                var host = ServiceBusBusFactoryConfiguratorExtensions.Host(sbc, serviceUri,
                                                                           h =>
                {
                    h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                        ConfigurationManager.AppSettings["AzureSbKeyName"],
                        ConfigurationManager.AppSettings["AzureSbSharedAccessKey"], TimeSpan.FromDays(1),
                        TokenScope.Namespace);
                });

                sbc.ReceiveEndpoint(host, "web.dev.endpoint", e =>
                {
                    // Configure your consumer(s)
                    ConsumerExtensions.Consumer <SignalRHandler>(e);
                    e.DefaultMessageTimeToLive = TimeSpan.FromMinutes(1);
                    e.EnableDeadLetteringOnMessageExpiration = false;
                });
            });

            return(bus);
        }
Ejemplo n.º 2
0
        private IBusControl GetBus(IContext context, Action <IServiceBusBusFactoryConfigurator, IServiceBusHost, int> configureReceiveEndpoint = null)
        {
            var appSettings      = context.GetInstance <IAppSettings>();
            var serviceNamespace = appSettings.Get("Microsoft.ServiceBus.Namespace", true);
            var sharedAccessKey  = appSettings.Get("Microsoft.ServiceBus.SharedAccessKey", true);
            var workerLimit      = appSettings.Get("WorkerLimit").Parse <int>() ?? 10;

            var busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
            {
                var serviceUri    = ServiceBusEnvironment.CreateServiceUri("sb", serviceNamespace, "CommonGround.Scrape.Service");
                var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", sharedAccessKey);

                var host = ServiceBusBusFactoryConfiguratorExtensions.Host(cfg, serviceUri, h =>
                {
                    h.TokenProvider    = tokenProvider;
                    h.OperationTimeout = TimeSpan.FromMinutes(4);
                    h.RetryLimit       = 1;
                });

                cfg.MaxConcurrentCalls = workerLimit;
                cfg.PrefetchCount      = workerLimit;
                cfg.UseConcurrencyLimit(workerLimit);

                configureReceiveEndpoint?.Invoke(cfg, host, workerLimit);
            });

            return(busControl);
        }
Ejemplo n.º 3
0
        public static IBusControl CreateBus(string endpoint)
        {
            var bus = Bus.Factory.CreateUsingAzureServiceBus(sbc =>
            {
                var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb",
                                                                        ConfigurationManager.AppSettings["AzureSbNamespace"],
                                                                        ConfigurationManager.AppSettings["AzureSbPath"]);

                ServiceBusBusFactoryConfiguratorExtensions.Host(sbc, serviceUri,
                                                                h =>
                {
                    h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                        ConfigurationManager.AppSettings["AzureSbKeyName"],
                        ConfigurationManager.AppSettings["AzureSbSharedAccessKey"], TimeSpan.FromDays(1),
                        TokenScope.Namespace);
                });
            });

            return(bus);
        }
Ejemplo n.º 4
0
        protected override void Load(ContainerBuilder builder)
        {
            // Creates our bus from the factory and registers it as a singleton against two interfaces
            builder.Register(c => Bus.Factory.CreateUsingAzureServiceBus(sbc =>
            {
                var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ConfigurationManager.AppSettings["AzureSbNamespace"], ConfigurationManager.AppSettings["AzureSbPath"]);

                var host = ServiceBusBusFactoryConfiguratorExtensions.Host(sbc, serviceUri, h =>
                {
                    h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(ConfigurationManager.AppSettings["AzureSbKeyName"], ConfigurationManager.AppSettings["AzureSbSharedAccessKey"], TimeSpan.FromDays(1), TokenScope.Namespace);
                });

                sbc.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ServiceQueueName"], e =>
                {
                    // Configure your consumer(s)
                    ConsumerExtensions.Consumer <SignalRHandler>(e);
                    e.DefaultMessageTimeToLive = TimeSpan.FromMinutes(1);
                    e.EnableDeadLetteringOnMessageExpiration = false;
                });
            }))
            .SingleInstance()
            .As <IBusControl>()
            .As <IBus>();
        }
Ejemplo n.º 5
0
        public void Register(ContainerBuilder builder)
        {
            builder.Register(context =>
            {
                return(Bus.Factory.CreateUsingAzureServiceBus(sbc =>
                {
                    var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb",
                                                                            ConfigurationManager.AppSettings["AzureSbNamespace"],
                                                                            ConfigurationManager.AppSettings["AzureSbPath"]);

                    var host = ServiceBusBusFactoryConfiguratorExtensions.Host(sbc, serviceUri,
                                                                               h =>
                    {
                        h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(
                            ConfigurationManager.AppSettings["AzureSbKeyName"],
                            ConfigurationManager.AppSettings["AzureSbSharedAccessKey"], TimeSpan.FromDays(1),
                            TokenScope.Namespace);
                    });

                    sbc.ReceiveEndpoint(host, "denormalizer.dev.endpoint", e =>
                    {
                        // Configure your consumer(s)
                        ConsumerExtensions.Consumer <DenormalizerHandler>(e);
                        e.DefaultMessageTimeToLive = TimeSpan.FromMinutes(1);
                        e.EnableDeadLetteringOnMessageExpiration = false;
                    });
                }));
            })
            .SingleInstance()
            .As <IBusControl>()
            .As <IBus>();
            //builder.RegisterType<SmartFleetObjectContext>().As<SmartFleetObjectContext>();
            builder.RegisterType <DbContextScopeFactory>().As <IDbContextScopeFactory>();

            Container = builder.Build();
        }