【发布时间】:2020-04-01 23:55:02
【问题描述】:
我正在使用 pub sub 与 spring boot 的集成,我的配置类如下所示:
@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);
}
}
所以现在,我只调用了 sendToPubSub 方法,该方法将有效负载从我的应用程序添加到主题中,如下所示:
@Autowired
private PubSubConfiguration.PubsubOutboundGateway outboundGateway;
// used line in my code wherever is needed.
outboundGateway.sendToPubsub(jsonInString);
以上代码仅适用于我从应用程序属性文件加载的一个主题。
但是现在我想让我的主题名称动态添加到messageSender中,该怎么做。
【问题讨论】:
标签: java spring spring-boot google-cloud-pubsub spring-cloud-gcp