Python 从pubsub回调函数返回值

Python 从pubsub回调函数返回值,python,callback,publish-subscribe,google-cloud-pubsub,Python,Callback,Publish Subscribe,Google Cloud Pubsub,我试图从pubsub回调函数中获取一个值 如果我在回调函数中打印message.data,我可以看到数据。我曾经尝试过stream\u pull\u future并制作了一个python类,但没有成功 project = 'project_id' topic = 'topic' subscription = "sub" timeout = 10.0 subscriber = pubsub_v1.SubscriberClient() subscription_path = subscriber.

我试图从pubsub回调函数中获取一个值

如果我在回调函数中打印message.data,我可以看到数据。我曾经尝试过stream\u pull\u future并制作了一个python类,但没有成功

project = 'project_id'
topic = 'topic'
subscription = "sub"
timeout = 10.0

subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
    project, subscription
)


def test_callback():
    callback_class = CallBackMethod()
    streaming_pull_future = subscriber.subscribe(
        subscription_path, callback=callback_class.callback()
    )

    time.sleep(30)

    print("streaming", streaming_pull_future.result())
    print("streaming_timeout", streaming_pull_future.result(timeout=timeout))

    decoded_string = streaming_pull_future.decode('utf-8')
    print("decoded_string", decoded_string)

    # other stuff with string


class CallBackMethod:
    def __init__(self, data=None):
        self.data = data

    @classmethod
    def callback(cls, message=None):
        info("Got message {}".format(message))
        if message is None:
            return
        return cls(message.data)

你说“没有成功”是什么意思?你有错误吗?您的意思是永远不会调用回调?请更准确地说明您收到的错误消息,以便其他人可以帮助您!