我目前正在实现一个Spring Boot应用程序,该应用程序对诸如的google云服务有很多依赖性PubSub
。spring boot自动配置为我创建了许多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
。但这似乎是一个hack。
如何在没有有效的GCP密钥等设置的情况下进行本地开发?还是只是阻碍开发,我应该使用活动密钥?
我建议使用Pub / Sub模拟器,以尽可能接近远程环境。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句