# Deploy Topology

There are some scenarios, such as when using Azure Functions, where it may be necessary to deploy the topology to the broker separately, without actually starting the service (and thereby consuming messages). To support this, MassTransit has a DeployTopologyOnly flag that can be specified when configuring the bus. When used with the DeployAsync method, a simple console application can be created that creates all the exchanges/topics, queues, and subscriptions/bindings.

To deploy the broker topology using a console application, see the example below.

namespace MicrosoftDeployTopology
{
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using ContainerConsumers;
    using MassTransit;
    using Microsoft.Extensions.DependencyInjection;

    public class Program
    {
        public static async Task Main()
        {
            var services = new ServiceCollection();

            services.AddMassTransit(x =>
            {
                x.AddConsumer<SubmitOrderConsumer>(typeof(SubmitOrderConsumerDefinition));

                x.SetKebabCaseEndpointNameFormatter();

                x.UsingRabbitMq((context, cfg) =>
                {
                    cfg.DeployTopologyOnly = true;

                    cfg.ConfigureEndpoints(context);
                });
            });

            var provider = services.BuildServiceProvider();

            var busControl = provider.GetRequiredService<IBusControl>();

            try
            {
                await busControl.DeployAsync(new CancellationTokenSource(TimeSpan.FromMinutes(2)).Token);

                Console.WriteLine("Topology Deployed");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to deploy topology: {0}", ex);
            }
        }
    }
}