public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { var messageContractSection = hostContext.Configuration.GetSection("Bus:MessageContract"); var connectionString = messageContractSection.GetValue <string>("ConnectionString"); var topic = messageContractSection.GetValue <string>("Topic"); var subscription = messageContractSection.GetValue <string>("Subscription"); var configuration = new ReceiverConfigurationAzureServiceBus <MessageErrorContract>(topic, subscription); configuration.ReceiveOnlyDeadLetter(); var credentials = new CredentialsAzureServiceBus(connectionString); services.AddAzureServiceBus(credentials) .AddBusReceiverFor <MessageErrorContract>(builder => builder.WithConfiguration(configuration)); services.AddHostedService <Worker>(); });
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { var azureServiceBusSection = hostContext.Configuration.GetSection("Bus:MessageContract:AzureServiceBus"); var connectionString = azureServiceBusSection.GetValue <string>("ConnectionString"); var topic = azureServiceBusSection.GetValue <string>("Topic"); var subscription = azureServiceBusSection.GetValue <string>("Subscription"); var maxConcurrentCalls = 1; var autoCompleteMessage = false; var configurationAzureServiceBus = new ReceiverConfigurationAzureServiceBus <MessageContractASB>(topic, subscription, maxConcurrentCalls, autoCompleteMessage); var credentialsAzureServiceBus = new CredentialsAzureServiceBus(connectionString); services .AddAzureServiceBus(credentialsAzureServiceBus) .AddBusReceiverFor <MessageContractASB>(builder => builder .WithConfiguration(configurationAzureServiceBus) .WithMessageHandler <ConsumerMessage>()); services.AddHostedService <WorkerAzureServiceBus>(); var rabbitMQBusSection = hostContext.Configuration.GetSection("Bus:MessageContract:RabbitMQ"); var hostName = rabbitMQBusSection.GetValue <string>("HostName"); var port = rabbitMQBusSection.GetValue <int>("Port"); var userName = rabbitMQBusSection.GetValue <string>("UserName"); var password = rabbitMQBusSection.GetValue <string>("Password"); var queue = rabbitMQBusSection.GetValue <string>("Queue"); var exchange = rabbitMQBusSection.GetValue <string>("Exchange"); var credentialsRabbitMQ = new CredentialsRabbitMQ(hostName, port, userName, password); var configurationRabbitMQ = new ReceiverConfigurationRabbitMQ <MessageContractRMQ>(exchange, queue); services .AddRabbitMQ(credentialsRabbitMQ) .AddBusReceiverFor <MessageContractRMQ>(builder => builder .WithConfiguration(configurationRabbitMQ) .WithMessageHandler <ConsumerMessageRMQ>()); services.AddHostedService <WorkerRabbitMQ>(); });
public static ReceiverBuilderFor <T> WithAzureServiceBus <T>(this ReceiverBuilderFor <T> receiver, ReceiverConfigurationAzureServiceBus <T> configuration, CredentialsAzureServiceBus credentials) { receiver.WithReceiver((pipeline, logger) => new ReceiverAzureServiceBusFor <T>(pipeline, configuration, credentials, logger)); return(receiver); }
public ServiceCollectionReceiverBuilderFor <T> WithConfiguration(ReceiverConfigurationAzureServiceBus <T> configuration) { WithReceiver <ReceiverAzureServiceBusFor <T> >(configuration); return(this); }