title: Azure Service Bus - Spring Boot disable autostart (com.microsoft.azure : azure-servicebus-spring-boot-starter)
body: <p>I have the following implementation to consume the message from Azure Service Bus using Spring Boot application however I want to be able to control the ServiceBusConsumer from automatically start listening to the Topic using Spring boot profile property</p>
  <p>something like this in the application.yaml</p>
  <pre><code> servicebus.consumer.enable=false
  </code></pre>
  <p>it should disable the ServiceBusConsumer from listening to the Topic(s) as well as I should be able to start the ServiceBusConsumer using a REST API - eg: ./api/servicebus/consumer/start?</p>
  <pre><code>import com.microsoft.azure.servicebus.ExceptionPhase;
  import com.microsoft.azure.servicebus.IMessage;
  import com.microsoft.azure.servicebus.IMessageHandler;
  import com.microsoft.azure.servicebus.ISubscriptionClient;
  import lombok.extern.log4j.Log4j2;
  import org.springframework.boot.context.event.ApplicationReadyEvent;
  import org.springframework.context.event.EventListener;
  import org.springframework.core.Ordered;
  import org.springframework.stereotype.Component;
  
  import java.util.concurrent.CompletableFuture;
  
  @Log4j2
  @Component
  class ServiceBusConsumer implements Ordered {
  
      private final ISubscriptionClient iSubscriptionClient;
  
      ServiceBusConsumer(ISubscriptionClient isc) {
          this.iSubscriptionClient = isc;
      }
  
      @EventListener(ApplicationReadyEvent.class)
      public void consume() throws Exception {
  
          this.iSubscriptionClient.registerMessageHandler(new IMessageHandler() {
  
              @Override
              public CompletableFuture&lt;Void&gt; onMessageAsync(IMessage message) {
                  log.info(&quot;received message &quot; + new String(message.getBody()) + &quot; with body ID &quot; + message.getMessageId());
                  return CompletableFuture.completedFuture(null);
              }
  
              @Override
              public void notifyException(Throwable exception, ExceptionPhase phase) {
                  log.error(&quot;eeks!&quot;, exception);
              }
          });
  
      }
  
      @Override
      public int getOrder() {
          return Ordered.HIGHEST_PRECEDENCE;
      }
  }
  </code></pre>