I am working on integration RabbitMQ and GCP Pub/Sub.
I am using Pika library with Python. Connection is established by BlockingConnection.
My consumer is running as separate thread. Max expected messages workload is up to 100 msg/s.
According some initial tests what I performed seems that solution is working, but I have some doubts how callback function is constructed. I am invoking publish method to publish to Pub/Sub in GCP and then in block try, basic_ack on processed message.
If somebody has experience in this area, could I ask to give some opinion about my solution and may be some examples how it could be implemented.
def consume_data_callback(self, basic_deliver, body):
# ... some code
future = self.publisher.publish(topic_path, self.payload.SerializeToString())
try:
message_id = future.result(timeout=1)
self.channel.basic_ack(basic_deliver.delivery_tag)
except Exception as e:
future.cancel()
_logger.error("Result after publishing Pub/Sub with: {}".format(e))
Thank you for answer.
I personally haven't tried it yet but I did searched for references that might help you. This RabbitMQ - Publish/Subscribe article has a callback code sample that can help you confirm if what you have written is an appropriate solution.
GitHub full code version: