title: Spring boot: push message to specific topic for each request
body: <p>I am using pub sub integration with spring boot, for which my configuration class look like this:</p>
  
  <pre><code>@Configuration
  public class PubSubConfiguration {
  
      @Value("${spring.pubsub.topic.name}")
      private String topicName;
  
      @Bean
      @ServiceActivator(inputChannel = "MyOutputChannel")
      public PubSubMessageHandler messageSender(PubSubTemplate pubsubTemplate) {
          return new PubSubMessageHandler(pubsubTemplate, topicName);
      }
  
      @MessagingGateway(defaultRequestChannel = "MyOutputChannel")
      public interface PubsubOutboundGateway {
          void sendToPubsub(String attribute);
      }
  
  }
  </code></pre>
  
  <p>So now, I was calling only sendToPubSub method which add payload into topic from my app, like this:</p>
  
  <pre><code>@Autowired
  private PubSubConfiguration.PubsubOutboundGateway outboundGateway;
  
  // used line in my code wherever is needed. 
  outboundGateway.sendToPubsub(jsonInString);
  </code></pre>
  
  <p>The above code is just meant for one topic which i loaded from application property file.</p>
  
  <p>But now I wanted to make my topic name is dynamically added into messageSender, how to do that.</p>