Our application uses Google PubSub(Publisher-Subscriber) for asynchronous communication across the services. At one of the services in the application, it checks if the topic(publisher) name exists or not in PubSub. If it doesn't exist in PubSub, the service has a logic to create topic(publisher) name at restart else it logs the message that the topic(publisher) name already exists in Google PubSub.
Description of Issue:
Summary:
// Reading the PubSub Configurations from file
File file = new File(ServiceConfigJson.PUBSUB_CONFIG_FILE_PATH);
InputStream stream = new FileInputStream(file);
// Authenticating and Checking whether topic name exists or not
AuthCredentials.ServiceAccountAuthCredentials auth = AuthCredentials.createForJson(stream);
pubsub = PubSubOptions.builder().projectId("anna-us").authCredentials(auth).build().service();
Topic pubSubTopic = pubsub.getTopic(topicName);
if (pubSubTopic == null)
{
// Creates the new topic
Topic topic = pubsub.create(TopicInfo.of(topicName));
logger.debug("PubSubTopic with topic name {} created", topic.name());
}
else
{
logger.info("PubSubTopic with topic name {} already exists", topicName);
}
It would be of great help if someone could give an insight on this.
Versions used:
compile group: 'com.google.cloud', name: 'google-cloud-pubsub', version: '0.4.0'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.931'
I have changed my dependency on Gradle by adding a library only for AWS S3 instead of the whole AWS SDK.
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.931'
to compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.934'
After changing this, PubSub started to work fine for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.