title: How to specify which Azure Service Bus Topic to use with MassTransit
body: <p>I've tried using MassTransit to publish a message to a topic named <code>events</code> in an Azure Service Bus. I have problems configuring MassTransit to use my predefined topic <code>events</code>, instead it creates a new topic named by the namespace/classname for the message type. So I wonder how to specify which topic to use instead of creating a new one.</p>
  <p>This is the code I've tested with:</p>
  <pre><code>using System;
  using System.Threading.Tasks;
  using MassTransit;
  using MassTransit.AzureServiceBusTransport;
  using Microsoft.ServiceBus;
  
  namespace PublisherNameSpace
  {
      public class Publisher
      {
          public static async Task PublishMessage()
          {
              var topic = &quot;events&quot;;
              var bus = Bus.Factory.CreateUsingAzureServiceBus(
                  cfg =&gt;
                  {
                      var azureServiceBusHost = cfg.Host(new Uri(&quot;sb://&lt;busname&gt;.servicebus.windows.net&quot;), host =&gt;
                      {
                          host.OperationTimeout = TimeSpan.FromSeconds(5);
                          host.TokenProvider =
                              TokenProvider.CreateSharedAccessSignatureTokenProvider(
                                  &quot;RootManageSharedAccessKey&quot;,
                                  &quot;&lt;key&gt;&quot;
                              );
                      });
  
                      cfg.ReceiveEndpoint(azureServiceBusHost, topic, e =&gt;
                      {
                          e.Consumer&lt;TestConsumer&gt;();
                      });
                  });
  
              await bus.Publish&lt;TestConsumer&gt;(new TestMessage { TestString = &quot;testing&quot; });
          }
      }
  
      public class TestConsumer : IConsumer&lt;TestMessage&gt;
      {
          public Task Consume(ConsumeContext&lt;TestMessage&gt; context)
          {
              return Console.Out.WriteAsync(&quot;Consuming message&quot;);
          }
      }
  
      public class TestMessage
      {
          public string TestString { get; set; }
      }
  }
  </code></pre>