[英]Local development with Google Cloud Spring dependencies
我目前正在實現一個 spring 啟動應用程序,它對像PubSub
這樣的谷歌雲服務有很多依賴。 spring 引導自動配置為我創建了許多 bean。 例如MessagingGateway
實現和PubSubTemplate
。
現在我有以下工件:
@Service
public class MyServiceImpl implements MyService {
private final PubsubOutboundGateway messagingGateway;
public MyServiceImpl(PubsubOutboundGateway messagingGateway) {
this.messagingGateway = messagingGateway;
}
@Override
public void sendToPubSub(String s) {
messagingGateway.sendTest(s);
}
}
@MessagingGateway
@Component
public interface PubsubOutboundGateway {
@Gateway(requestChannel = "myChannel" )
void sendTest(String test);
}
@Configuration
public class Channels {
@Bean
@ServiceActivator(inputChannel = "myChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
return new PubSubMessageHandler(pubsubTemplate, "my-topic");
}
}
當我關閉 pubsub 進行本地開發時,出現以下錯誤
Consider defining a bean of type 'com.google.cloud.spring.pubsub.core.PubSubTemplate' in your configuration.
但我真正想要的是一個僅打印消息的本地 PubsubOutboundGateway。 我可以通過將@Profile("!local")
添加到PubsubOutboundGateway
和Channels
並實現PubsubOutboundGatewayLocalImpl
來實現這一點。 但這似乎是一個黑客。
如何在沒有活動 GCP 密鑰等設置的情況下執行本地開發? 還是這只會阻礙開發,我應該使用活動密鑰?
我建議使用Pub/Sub 模擬器,以便盡可能接近遠程環境。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.