2012-03-09 8 views
1

呼び出すことはできません、私はブローカーに公開しようとしてると:メッセージ - 例外TypeError「str」はオブジェクトがJSONに私のメッセージペイロードをコードした後

connection = establish_connection() 
producer = Producer(channel=connection, 
         exchange="inbound", 
         routing_key="apisubmit") 

producer.publish(body=pl,headers={"api_access_key": "xxxx", "client_id": 4, "object_type": "location", "action": "c"}) 

は、Djangoは以下を返して:

Traceback: 
File "/usr/local/pythonenv/openblock/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/core/handlers/base.py" in get_response 
    111.       response = callback(request, *callback_args, **callback_kwargs) 
File "/usr/local/pythonenv/openblock/src/myblock/myblock/barz/views.py" in testtwo 
    19.  msg=publish_kombu() 
File "/usr/local/pythonenv/openblock/src/myblock/myblock/barz/messaging.py" in publish_kombu 
    99.       routing_key="apisubmit") 
File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py" in __init__ 
    82.   self.exchange = self.exchange(self.channel) 

Exception Type: TypeError at /barz/publish_kombu/ 
Exception Value: 'str' object is not callable 

答えて

2

Producer.exchangeは、Exchangeである必要があります。デフォルトではExchange("")ですが、なんとかそれを文字列に設定する必要があります。

0

交換」に値を渡したことがありましたら、それはExchangeオブジェクトである必要があります。 - docs

exchange = Exchange(name='inbound') # the minimal declaration 
connection = establish_connection() 
producer = Producer(channel=connection, 
         exchange=exchange, 
         routing_key="apisubmit") 

producer.publish(body=pl,headers={"api_access_key": "xxxx", "client_id": 4, "object_type": "location", "action": "c"}) 

為替のparamの完全なリストについては:

あなたのコードがなければなりません。


私は

queue = Queue(name=queue_name, exchange='host_tasks', routing_key=binding_key) 
bound_queue = queue(channel) # only once bound, we can call declare(), purge(), delete() on exchange 

だから取引を宣言し、すなわち、

exchange = Exchange('host_tasks', 'direct', durable=True) 
queue = Queue(name=queue_name, exchange=exchange, routing_key=binding_key) 
bound_queue = queue(channel) 

thahなどがimport Exchange

に忘れてはいけないキュー宣言で同じエラーが発生しました
関連する問題