private async Task <ServiceBusMessageProcessorClientProvider> Factory() { var client = new Microsoft.Azure.Management.ServiceBus.ServiceBusManagementClient(new TokenCredentials(await keyVaultService.GetTokenAsync())); client.SubscriptionId = options.SubscriptionId.ToString(); var conn = await client.Namespaces.ListKeysWithHttpMessagesAsync(options.ResourceGroup, options.Namespace, options.AuthorizationRuleName); var correlationsMap = new Dictionary <string, EntityDescription> { { "default", new QueueDescription("earthml-default") }, { "EarthML.Identity", new QueueDescription("earthml-identity") }, { "EarthML.Pimetr", new QueueDescription("earthml-pimetr") }, { "EarthML.Notifications", new TopicDescription("signalr") } }; foreach (var correlation in correlations) { var(key, value) = correlation.Create(); correlationsMap.Add(key, value); } return(new ServiceBusMessageProcessorProvider(loggerFactory, new ServiceBusMessageProcessorProviderOptions { ConnectionString = conn.Body.PrimaryConnectionString, TopicScaleCount = 2, TopicDescription = new TopicDescription("earthml-documents"), SubscriptionDescription = new SubscriptionDescription("earthml-documents", "sub"), CorrelationToQueueMapping = correlationsMap, CorrelationIdProvider = CorrelationIdProvider })); }
private async Task <IMessageProcessorClient> CreateProcessor() { var client = new Microsoft.Azure.Management.ServiceBus.ServiceBusManagementClient(new TokenCredentials(await keyVaultService.GetTokenAsync())); client.SubscriptionId = busOptions.SubscriptionId.ToString(); var conn = await client.Namespaces.ListKeysWithHttpMessagesAsync(busOptions.ResourceGroup, busOptions.Namespace, busOptions.AuthorizationRuleName); return(new MessageProcessorClient <Message>( loggerFactory.CreateLogger <MessageProcessorClient <Message> >(), new MessageProcessorClientOptions <Message> { Provider = new ServiceBusMessageProcessorProvider(loggerFactory, new ServiceBusMessageProcessorProviderOptions { ConnectionString = conn.Body.PrimaryConnectionString, MaxConcurrentProcesses = options.ConcurrentMessagesProcesses, //High IO depended message processing for relocation of data and reordering. MaxMessageRetries = 3, QueueDescription = new QueueDescription(options.QueuePath), }), HandlerTimeOut = TimeSpan.FromMinutes(60), ResolverProvider = () => new HandlerResolver(serviceScopeFactory.CreateScope()), // return new UnityHandlerResolver(container); }, IdleTimeCheckInterval = TimeSpan.FromMinutes(5), Notifications = new DefaultNotifications { OnIdleNotification = (m) => { logger.LogInformation("Idling for {idleMinutes} mins and {idleSecs} secs", m.IdleTime.Minutes, m.IdleTime.Seconds); return Task.FromResult(0); }, OnMessageStarted = (notice) => { // CallContext.LogicalSetData(ItemCorrelationTelemetryInitializer.DEFAULT_CORRELATION_SLOT, notice.Message.MessageId); Trace.CorrelationManager.ActivityId = Guid.NewGuid(); return Task.FromResult(0); }, OnMovingMessageToDeadLetter = (notice) => { // Trace.TraceWarning("MovingMessageToDeadLetter: {0}", notice.Message.GetType().Name); TelemetryClient rtClient = (TelemetryClient)notice.Resolver.GetHandler(typeof(TelemetryClient)); var t = new EventTelemetry("MovingMessageToDeadLetter") { Timestamp = DateTimeOffset.Now, }; t.Properties.Add("MessageId", notice.Message.MessageId); t.Properties.Add("MessageType", notice.Message.GetType().Name); rtClient.TrackEvent(t); return Task.FromResult(0); }, OnMessageCompleted = async(notice) => { // await notice.TrackMessageCompletedAsync(); } } })); }
public Deploy(ILogger Logger) { var Deploy_ClientId = ConfigurationManager.AppSettings["Deploy_ClientId"]; var Deploy_ClientSecret = ConfigurationManager.AppSettings["Deploy_ClientSecret"]; var Deploy_TenantId = ConfigurationManager.AppSettings["Deploy_TenantId"]; var Deploy_SubscriptionId = ConfigurationManager.AppSettings["Deploy_SubscriptionId"]; var Deploy_ResourceGroupName = ConfigurationManager.AppSettings["Deploy_ResourceGroupName"]; var Deploy_ServiceBusNamespaceName = ConfigurationManager.AppSettings["Deploy_ServiceBusNamespaceName"]; var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(Deploy_ClientId, Deploy_ClientSecret, Deploy_TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, Deploy_SubscriptionId); _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(Deploy_ResourceGroupName, Deploy_ServiceBusNamespaceName); _serviceBusManagementClient = new Microsoft.Azure.Management.ServiceBus.ServiceBusManagementClient(credentials) { SubscriptionId = Deploy_SubscriptionId }; _log = Logger; }