मैं RabbitMQ का उपयोग कर एक अजगर उपभोक्ता के लिए एक अजगर निर्माता से एक अजगर शब्दकोश भेजने की कोशिश कर रहा हूँ। निर्माता पहले स्थानीय RabbitMQ सर्वर से कनेक्शन स्थापित करता है। फिर यह एक कतार बनाता है जिस पर संदेश वितरित किया जाएगा, और अंततः संदेश भेजता है। उपभोक्ता पहले RabbitMQ सर्वर से जुड़ता है और फिर सुनिश्चित करता है कि कतार एक ही कतार बनाकर मौजूद है। इसके बाद इसे कॉलबैक फ़ंक्शन के भीतर निर्माता से संदेश प्राप्त होता है, और 'आईडी' मान (1) प्रिंट करता है। यहाँ उत्पादक और उपभोक्ता के लिए स्क्रिप्ट हैं:RabbitMQ: कैसे अजगर उत्पादक और उपभोक्ता के बीच अजगर शब्दकोश भेजने के लिए?
producer.py स्क्रिप्ट:
import pika
import sys
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
message = {'id': 1, 'name': 'name1'}
channel.basic_publish(exchange='',
routing_key='task_queue',
body=message,
properties=pika.BasicProperties(
delivery_mode = 2, # make message persistent
))
print(" [x] Sent %r" % message)
connection.close()
consumer.py स्क्रिप्ट:
import pika
import time
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
print(' [*] Waiting for messages. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
print(body['id'])
print(" [x] Done")
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queue='task_queue')
channel.start_consuming()
लेकिन, जब मैं producer.py चलाने के लिए, मैं इस मिल त्रुटि:
line 18, in <module>
delivery_mode = 2, # make message persistent
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 1978, in basic_publish
mandatory, immediate)
File "/Library/Python/2.7/site-packages/pika/adapters/blocking_connection.py", line 2064, in publish
immediate=immediate)
File "/Library/Python/2.7/site-packages/pika/channel.py", line 338, in basic_publish
(properties, body))
File "/Library/Python/2.7/site-packages/pika/channel.py", line 1150, in _send_method
self.connection._send_method(self.channel_number, method_frame, content)
File "/Library/Python/2.7/site-packages/pika/connection.py", line 1571, in _send_method
self._send_message(channel_number, method_frame, content)
File "/Library/Python/2.7/site-packages/pika/connection.py", line 1596, in _send_message
content[1][s:e]).marshal())
TypeError: unhashable type
किसी को भी मेरी मदद कर सकते हैं? धन्यवाद!
आप एक json वस्तु को अपने संदेश में परिवर्तित करने का प्रयास करें और फिर भेज सकते हैं। –