Created
January 27, 2021 00:35
-
-
Save maldworth/7fa7b4891a0e437a707bcd39f804eb7b to your computer and use it in GitHub Desktop.
Azure Service Bus Deploy Topology Console App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static async Task Main(string[] args) | |
{ | |
// Setup configuration | |
IConfiguration configuration = new ConfigurationBuilder() | |
.AddEnvironmentVariables() | |
.AddCommandLine(args) | |
.Build(); | |
//setup our DI | |
var serviceCollection = new ServiceCollection() | |
.AddLogging(loggerBuilder => | |
{ | |
loggerBuilder.AddConsole(); | |
}) | |
// Setup Bus | |
.AddMassTransit(cfg => | |
{ | |
cfg.AddSagaStateMachine<SomeStateMachine, SomeStateEntity>(typeof(SomeStateMachineDefinition)) | |
.InMemoryRepository(); | |
cfg.SetKebabCaseEndpointNameFormatter(); | |
cfg.AddConsumersFromNamespaceContaining<SomeConsumer>(); | |
cfg.UsingAzureServiceBus((x, y) => | |
{ | |
y.DeployTopologyOnly = true; | |
y.Host(configuration["azureConnStr"]); | |
y.ConfigureEndpoints(x); | |
}); | |
}); | |
using (var serviceProvider = serviceCollection.BuildServiceProvider()) | |
{ | |
var logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger<Program>(); | |
logger.LogInformation("Deploying Topology..."); | |
var bus = serviceProvider.GetRequiredService<IBusControl>(); | |
await bus.StartAsync(); | |
await Task.Delay(5000); | |
logger.LogInformation("Topology Deployed, stopping bus..."); | |
await bus.StopAsync(); | |
logger.LogInformation("Bus Stopped."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your deploy pipeline, execute with
dotnet TheConsoleApp.dll --azureConnStr 'your-full-azure-sb-conn-string'