Skip to content

Instantly share code, notes, and snippets.

@maldworth
Created January 27, 2021 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maldworth/7fa7b4891a0e437a707bcd39f804eb7b to your computer and use it in GitHub Desktop.
Save maldworth/7fa7b4891a0e437a707bcd39f804eb7b to your computer and use it in GitHub Desktop.
Azure Service Bus Deploy Topology Console App
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.");
}
}
}
@maldworth
Copy link
Author

In your deploy pipeline, execute with
dotnet TheConsoleApp.dll --azureConnStr 'your-full-azure-sb-conn-string'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment