def getMessage1(self, id, queueName):
uuid = id
def onMessage(ch, method, properties, body):
if uuid in body:
requeued_messages = self.channel.stop_consuming()
return body
self.channel.basic_consume(consumer_callback = onMessage, queue = queueName, no_ack = True)
self.channel.start_consuming()
return onMessage(ch, method, properties, body)
#global name 'ch' is not defined
我想要定義兩個函數,如代碼中所示。我試圖將body
返回到內部函數,我也想要body
返回到我的外部函數,即getMessage1
。Python中的內函數
但是這上面的代碼返回我
「功能的onMessage在0x0000000006642128」不是「身體」
,也是我想要得到的出來循環我的內部函數只當uuid
存在於body
中時。
返回body
是一個字符串
這裏要說的是,我使用
def basic_consume(self, consumer_callback,
queue='',
no_ack=False,
exclusive=False,
consumer_tag=None,
arguments=None):
"""Sends the AMQP command Basic.Consume to the broker and binds messages
for the consumer_tag to the consumer callback. If you do not pass in
a consumer_tag, one will be automatically generated for you. Returns
the consumer tag.
For more information on basic_consume, see:
http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.consume
:param method consumer_callback: The method to callback when consuming
with the signature consumer_callback(channel, method, properties,
body), where
channel: pika.Channel
method: pika.spec.Basic.Deliver
properties: pika.spec.BasicProperties
body: str, unicode, or bytes
請檢查https://stackoverflow.com/help/mcve 您的發佈代碼不完整。 – renemilk