Reputation:
I'm currently implementing a spring boot application with quite a few dependencies on google cloud services like PubSub
. The spring boot autoconfiguration creates a number of beans for me.
For example a MessagingGateway
implementation and a PubSubTemplate
.
Now I have the following artifacts:
@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");
}
}
When I turn off pubsub for local development, I get the following error
Consider defining a bean of type 'com.google.cloud.spring.pubsub.core.PubSubTemplate' in your configuration.
But what I really want is a local PubsubOutboundGateway that just prints the messages.
I can achieve this by adding @Profile("!local")
to PubsubOutboundGateway
and Channels
and implement a PubsubOutboundGatewayLocalImpl
. But this seems like a hack.
How can perform local development without having an active GCP key etc. setup? Or does that just hinder development and I should use an active key?
Upvotes: 0
Views: 368
Reputation: 76807
I'd suggest to use the Pub/Sub emulator, in order to get as close to the remote environment as possible.
Upvotes: 0