I'm trying to use Google PubSub to pass and receive messages between two services. However, some of the messages sent seem to be randomly dropped, and are not processed by the subscriber's callback method.
When sending messages, about half the messages are processed by the callback method. For the other half, the callback method does not appear to be called at all (No info is logged). However, the messages still disappear from the topic, and are not resent.
The code used for starting the subscriber:
logger = logging.getLogger(LOGGER_NAME)
logger.info('Starting the pubsub subscriber')
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(GOOGLE_CLOUD_PROJECT, SUBSCRIPTION_NAME)
subscriber.subscribe(subscription_path, callback=callback)
while True:
try:
sleep(60)
except Exception as e:
// Log exception
The callback method:
def callback(message):
logger = logging.getLogger(LOGGER_NAME)
logger.info(f'Recieved callback with message: {message}', extra = {'callback_message': message} )
// Process message
The error appears to be on the subscriber side. The messages are sent from the publisher, and if a subscriber is not connected to the topic the messages do not disappear.
I've tried to use Flow Control to control the number of messages retrieved by the subscriber, but it does not appear to have any effect.
Can the messages be processed without invoking the callback method? Are there some other reasons why messages may disappear from the topic?
EDIT: Turns out another service was reading from the same subscription, processing the missing messages.
I know you found the answer to your problem, but I thought it would be worthwhile to list some useful steps for debugging this type of problem:
subscription/oldest_unacked_message_age
and subscription/num_undelivered_messages
via Stackdriver . If after checking all of that you are unsure what is happening to your messages, it is best to contact support with the name of your project and subscription as well as the IDs of any messages you think were not delivered.
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.