private async Task <MessageReceiver> CreateMessageReceiverAsync(AzureServiceBusMessagePumpSettings messagePumpSettings) { var rawConnectionString = await messagePumpSettings.GetConnectionStringAsync(); var serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(rawConnectionString); MessageReceiver messageReceiver; if (string.IsNullOrWhiteSpace(serviceBusConnectionStringBuilder.EntityPath)) { // Connection string doesn't include the entity so we're using the message pump settings if (string.IsNullOrWhiteSpace(messagePumpSettings.EntityName)) { throw new ArgumentException("No entity name was specified while the connection string is scoped to the namespace"); } messageReceiver = CreateReceiver(serviceBusConnectionStringBuilder, messagePumpSettings.EntityName, SubscriptionName); } else { // Connection string includes the entity so we're using that instead of the message pump settings messageReceiver = CreateReceiver(serviceBusConnectionStringBuilder, serviceBusConnectionStringBuilder.EntityPath, SubscriptionName); } Namespace = messageReceiver.ServiceBusConnection?.Endpoint?.Host; ConfigurePlugins(); RegisterClientInformation(messageReceiver.ClientId, messageReceiver.Path); return(messageReceiver); }
private MessageHandlerOptions DetermineMessageHandlerOptions(AzureServiceBusMessagePumpSettings messagePumpSettings) { var messageHandlerOptions = new MessageHandlerOptions(exceptionReceivedEventArgs => HandleReceiveExceptionAsync(exceptionReceivedEventArgs.Exception)); if (messagePumpSettings.Options != null) { // Assign the configured defaults messageHandlerOptions.AutoComplete = messagePumpSettings.Options.AutoComplete; messageHandlerOptions.MaxConcurrentCalls = messagePumpSettings.Options.MaxConcurrentCalls ?? messageHandlerOptions.MaxConcurrentCalls; Logger.LogInformation("Message pump options were configured instead of Azure Service Bus defaults."); } else { Logger.LogWarning("No message pump options were configured, using Azure Service Bus defaults instead."); } return(messageHandlerOptions); }
/// <summary> /// Initializes a new instance of the <see cref="AzureServiceBusMessagePump"/> class. /// </summary> /// <param name="settings">Settings to configure the message pump</param> /// <param name="applicationConfiguration">Configuration of the application</param> /// <param name="serviceProvider">Collection of services that are configured</param> /// <param name="messageRouter">The router to route incoming Azure Service Bus messages through registered <see cref="IAzureServiceBusMessageHandler{TMessage}"/>s.</param> /// <param name="logger">Logger to write telemetry to</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="settings"/>, <paramref name="settings"/>, <paramref name="serviceProvider"/>, <paramref name="messageRouter"/> is <c>null</c>.</exception> public AzureServiceBusMessagePump( AzureServiceBusMessagePumpSettings settings, IConfiguration applicationConfiguration, IServiceProvider serviceProvider, IAzureServiceBusMessageRouter messageRouter, ILogger <AzureServiceBusMessagePump> logger) : base(applicationConfiguration, serviceProvider, logger) { Guard.NotNull(settings, nameof(settings), "Requires a set of settings to correctly configure the message pump"); Guard.NotNull(applicationConfiguration, nameof(applicationConfiguration), "Requires a configuration instance to retrieve application-specific information"); Guard.NotNull(serviceProvider, nameof(serviceProvider), "Requires a service provider to retrieve the registered message handlers"); Guard.NotNull(messageRouter, nameof(messageRouter), "Requires a message router to route incoming Azure Service Bus messages through registered message handlers"); Settings = settings; JobId = Settings.Options.JobId; SubscriptionName = Settings.SubscriptionName; _messageRouter = messageRouter; _loggingScope = logger.BeginScope("Job: {JobId}", JobId); }