# Topology

In MassTransit, Topology is how message types are used to configure broker topics (exchanges in RabbitMQ) and queues. Topology is also used to access specific broker capabilities, such as RabbitMQ direct exchanges and routing keys.

Topology is separate from the send, publish, and consume pipelines which are focused more on middleware inside MassTransit. Topology allows conventions to be created that can create message-specific topology configuration at runtime as messages are published and sent.

# Bus Topology

Once the bus is created, access to topology is via the Topology property on IBus. The IBusTopology interface is shown below.

namespace MassTransit.Topology
{
    using System;


    public interface IBusTopology
    {
        IPublishTopology PublishTopology { get; }

        ISendTopology SendTopology { get; }

        /// <summary>
        /// Returns the publish topology for the specified message type
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <returns></returns>
        IMessagePublishTopology<T> Publish<T>()
            where T : class;

        /// <summary>
        /// Returns the send topology for the specified message type
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <returns></returns>
        IMessageSendTopology<T> Send<T>()
            where T : class;

        /// <summary>
        /// Returns the message topology for the specified message type
        /// </summary>
        /// <typeparam name="T">The message type</typeparam>
        /// <returns></returns>
        IMessageTopology<T> Message<T>()
            where T : class;

        /// <summary>
        /// Returns the destination address for the specified message type, as a short address.
        /// </summary>
        /// <param name="messageType">The message type</param>
        /// <param name="publishAddress"></param>
        /// <returns></returns>
        bool TryGetPublishAddress(Type messageType, out Uri publishAddress);

        /// <summary>
        /// Returns the destination address for the specified message type, as a short address.
        /// </summary>
        /// <param name="publishAddress"></param>
        /// <returns></returns>
        bool TryGetPublishAddress<T>(out Uri publishAddress)
            where T : class;
    }
}

The message, publish, and send topologies can be accessed using this interface. It is also possible to retrieve a message's publish address. The Topology property may support other interfaces, such as a transport-specific host topology. Pattern matching can be used to check the host topology type as shown below.

namespace BusHostTopologyMatch
{
    using System;
    using System.Threading.Tasks;
    using BatchingConsumer;
    using MassTransit;
    using MassTransit.Azure.ServiceBus.Core;
    using MassTransit.Azure.ServiceBus.Core.Topology;

    public class Program
    {
        public static async Task Main()
        {
            var busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
            {
                cfg.Host("connection-string");
            });

            if (busControl.Topology is IServiceBusHostTopology serviceBusTopology)
            {

            }
        }
    }
}