I am migrating from 3.4.2 to 5.0.2 of spring-cloud-gcp-dependencies
Now I am facing this error:
constructor DefaultSubscriberFactory in class com.google.cloud.spring.pubsub.support.DefaultSubscriberFactory cannot be applied to given types;
Here is my current code:
The class configuration is annotated with:
@Configuration
@AutoConfigureAfter(GcpPubSubAutoConfiguration.class)
@ImportAutoConfiguration(exclude =
GcpPubSubReactiveAutoConfiguration.class)
public class PubSubConfiguration {
...
}
@Bean
public GcpProjectIdProvider gcpProjectIdProvider(final ApplicationProperties applicationProperties) {
return new DefaultGcpProjectIdProvider() {
@Override
public String getProjectId() {
return applicationProperties.getGcpProjectId();
}
};
}
@Bean
@Qualifier("mySubscriberFactory")
public DefaultSubscriberFactory mySubscriberFactory(
GcpProjectIdProvider gcpProjectIdProvider,
ApplicationProperties applicationProperties
) throws IOException {
final DefaultSubscriberFactory defaultSubscriberFactory = new DefaultSubscriberFactory(gcpProjectIdProvider); >>> the error is here
var serviceAccountCredentials = ServiceAccountCredentials.fromStream(
new ByteArrayInputStream(applicationProperties.getGoogleCloudStorage().getAuthentication().getBytes()));
defaultSubscriberFactory.setCredentialsProvider(FixedCredentialsProvider.create(serviceAccountCredentials));
return defaultSubscriberFactory;
}
@Bean
@Qualifier("myPubSubTemplate")
public PubSubTemplate mercareonPubSubTemplate(
GcpProjectIdProvider gcpProjectIdProvider,
@Qualifier("mySubscriberFactory") SubscriberFactory subscriberFactory
) {
return new PubSubTemplate(new DefaultPublisherFactory(gcpProjectIdProvider), subscriberFactory);
}
It is suggesting
DefaultSubscriberFactory(GcpProjectIdProvider) Use DefaultSubscriberFactory(GcpProjectIdProvider, PubSubConfiguration) instead
How to pass PubSubConfiguration ?
I fixed the problem by this way (example of code):
}