当前位置:首页 > 开发 > 开源软件 > 正文

celery+ rabbitMq + python window是下配置

发表于: 2012-02-17   作者:cooler1217   来源:转载   浏览:
摘要: 此过程非常复杂 , 我就把整个过程记录下来  。。。 1 python2.7.2  安装。。。不解释 2 celery 安装 不解释  http://celeryproject.org/ 3 例子 运行。。。 咔嚓,出错了。。。    异常:     :\Python27\lib\site-package
此过程非常复杂 , 我就把整个过程记录下来  。。。

1 python2.7.2  安装。。。不解释
2 celery 安装 不解释  http://celeryproject.org/
3 例子 运行。。。 咔嚓,出错了。。。
   异常:
    :\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\loaders\default.py:45: NotConfigured: No 'celeryconfig' module found! Please make sure it exists and is available to Python.
  "is available to Python." % (configname, )))

原因:每个工程都要有celeryConfig.py 
补上: 内容
import sys
import os
sys.path.insert(0, os.getcwd())

CELERY_IMPORTS = ("tasks", )

CELERY_RESULT_BACKEND = "amqp"

BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "guest"
BROKER_PASSWORD = "guest"
BROKER_VHOST = "/"



4 继续运行 (做个梦。。。成功了)
           现实比较残酷....
  异常:
Traceback (most recent call last):
  File "D:\workspace\testCelery\src\tasks.py", line 12, in <module>
    result = add.delay(4,4)
  File "C:\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\app\task\__init__.py", line 338, in delay
    return self.apply_async(args, kwargs)
  File "C:\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\app\task\__init__.py", line 444, in apply_async
    publish = publisher or self.app.amqp.publisher_pool.acquire(block=True)
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\connection.py", line 666, in acquire
    R = self.prepare(self.new())
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\pools.py", line 55, in prepare
    p = p()
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\pools.py", line 46, in <lambda>
    return lambda: self.create_producer()
  File "C:\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\app\amqp.py", line 264, in create_producer
    pub = self.app.amqp.TaskPublisher(conn, auto_declare=False)
  File "C:\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\app\amqp.py", line 325, in TaskPublisher
    return TaskPublisher(*args, **self.app.merge(defaults, kwargs))
  File "C:\Python27\lib\site-packages\celery-2.4.6-py2.7.egg\celery\app\amqp.py", line 157, in __init__
    super(TaskPublisher, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\compat.py", line 61, in __init__
    super(Publisher, self).__init__(connection, self.exchange, **kwargs)
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\messaging.py", line 69, in __init__
    channel = channel.default_channel
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\connection.py", line 593, in default_channel
    self.connection
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\connection.py", line 586, in connection
    self._connection = self._establish_connection()
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\connection.py", line 546, in _establish_connection
    conn = self.transport.establish_connection()
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\transport\amqplib.py", line 252, in establish_connection
    connect_timeout=conninfo.connect_timeout)
  File "C:\Python27\lib\site-packages\kombu-2.1.0-py2.7.egg\kombu\transport\amqplib.py", line 62, in __init__
    super(Connection, self).__init__(*args, **kwargs)
  File "build\bdist.win32\egg\amqplib\client_0_8\connection.py", line 129, in __init__
  File "build\bdist.win32\egg\amqplib\client_0_8\transport.py", line 281, in create_transport
  File "build\bdist.win32\egg\amqplib\client_0_8\transport.py", line 85, in __init__
socket.error: [Errno 10061]

找啊找。。。什么原因呢?
思绪万千。。。乱乱乱。。。
叮咚: 你光有worker,没有消息队列。。。他肯定不知道干啥,因为你rabbitMq还没装。。。

5  开始装rabbitMq。。。 http://www.rabbitmq.com/download.html
   下载,安装。。。请先安装erlang。。。。  http://www.erlang.org/download.html
    好吧,继续下载erlang。。。。
    等待ing。。。
    等待ing。。。。。
6   安装erlang。。。bingo
    安装rabbitMq。。。bingo
7   运行。。。还是不行,在研究。。。

bingo 找到了。。。
     因为是任务模式,你启动了这个任务,就要新花一个程序调用这个任务,才会执行
     我的是windows系统,所以比较麻烦。。
     步骤如下:
       1) 先进入工程目录
          cd D:\workspace\testCelery\src
       2)z执行命令,启动任务线程
          python C:\Python27\Lib\site-packages\celery-2.4.6-py2.7.egg\celery\bin\celeryd.py -l info -I tasks
       3) 然后在执行你编写的调用任务的python文件就可以了。。
测试:
>>> result = add.delay(4, 4)

>>> result.ready() # returns True if the task has finished processing.
False

>>> result.result # task is not ready, so no return value yet.
None

>>> result.get()   # Waits until the task is done and returns the retval.
8

>>> result.result # direct access to result, doesn't re-raise errors.
8

>>> result.successful() # returns True if the task didn't end in failure.
True
          
    大功告成~~~

   总结 :
     一、celery是调用rabbitMq的消息队列用的,所以必须先装rabbitMq,而rabbit是用erlang写的,还要装erlang环境,这个rabbitmq在安装的时候会进行提醒
     二、先启动消息队列服务起rabbitmq,然后启动你编写的执行任务线程,然后在去编写任务去执行
     三、windos每次在命令行下启动,不停的打路径,故写一个简单的批处理,进行任务启动  代码如下

    D:
cd D:\workspace\testCelery\src
python C:\Python27\Lib\site-packages\celery-2.4.6-py2.7.egg\celery\bin\celeryd.py -l info -I tasks
   语法就是不停的罗列你在命令行下输入的内容就行,然后命名为bat,双击执行,你的任务线程就启动了~~
   一点分享,尊重原著,哈哈哈。。。

    到此结束,开始应用!!

如果您觉得有用,记得赞一个,留言一下,对我鼓励一下~~
         

celery+ rabbitMq + python window是下配置

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号