2012-03-09 4 views
1

JSON으로 내 메시지 페이로드를 인코딩 한 후 호출하지, 내가 가진 브로커에 게시하려고 해요 :메시지가 다시마를 사용하여 출판 - 형식 오류 'STR'개체가

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"}) 

장고하면 다음을 반환 :

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.exchangeExchange이어야합니다. 기본적으로 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, 같은 thah

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

import Exchange

하는 것을 잊지 마세요 선언