Reputation: 166
I have a spring boot application in which I am creating a subscriber by passing subscription id at the time of application start
import com.google.cloud.pubsub.v1.MessageReceiver;
import com.google.cloud.pubsub.v1.Subscriber;
import com.google.pubsub.v1.ProjectSubscriptionName;
...
...
public void startAndWait() {
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectName, subscriptionId);
Subscriber subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
log.log(Level.INFO, "Created Subscriber: " + subscriptionName); // I get this logger message when service starts
subscriber.startAsync();
}
Following is the code for receiver that is passed to this subscriber while initialization in above code.
import com.google.cloud.pubsub.v1.AckReplyConsumer;
import com.google.cloud.pubsub.v1.MessageReceiver;
import com.google.pubsub.v1.PubsubMessage;
..
..
@Log
@Component
@Configurable
public class SubMessageReceiver implements MessageReceiver {
..
..
@Override
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
try {
processMessage(message);
} catch (IOException e) {
log.log(Level.SEVERE, "retrieving message content failed");
} catch (Exception e) {
log.log(Level.SEVERE, "Failed triggering rules");
}
consumer.ack();
}
I tried - manually deleting and again creating subscriptions, Manually publishing multiple messages on the topic and verified that those are received by subscription on google cloud console. The only issue is the receiveMessage method from client library is not getting the message ever! I verified that there is no other subscriber with the same subscription id I am using (not on any other environments either) I verified that the message queue is not full with unAcked messages.
I am expecting some loggers printed in my processMessage method mentioned above, or when I place debugger inside this method it should stop at the debug pointer whenever message arrives.
Please support or post any ideas! TIA!
Upvotes: 1
Views: 1758
Reputation: 166
There was no change in the code but I was able to make it work with downgrading version of google pub/sub maven library.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.56.0</version>
</dependency>
Now it works as expected for all the messages on the given topic. Hope it will help someone.
Upvotes: 2