コード例 #1
0
 def test_hash(self):
     self.assertEqual(hash(Exchange('a')), hash(Exchange('a')))
     self.assertNotEqual(hash(Exchange('a')), hash(Exchange('b')))
コード例 #2
0
 def test_set_persistent_delivery_mode(self):
     exc = Exchange("foo", "direct", delivery_mode="persistent")
     self.assertEqual(exc.delivery_mode, Exchange.PERSISTENT_DELIVERY_MODE)
コード例 #3
0
 def test_create_message(self):
     chan = get_conn().channel()
     Exchange("foo", channel=chan).Message({"foo": "bar"})
     self.assertIn("prepare_message", chan)
コード例 #4
0
 def setUp(self):
     self.exchange = Exchange("foo", "direct")
コード例 #5
0
 def test_can_cache_declaration(self):
     self.assertTrue(Exchange("a", durable=True).can_cache_declaration)
     self.assertFalse(Exchange("a", durable=False).can_cache_declaration)
コード例 #6
0
 def setUp(self):
     self.connection = BrokerConnection(transport=Transport)
     self.connection.connect()
     self.assertTrue(self.connection.connection.connected)
     self.exchange = Exchange("foo", "direct")
コード例 #7
0
# CELERYD_POOL_RESTARTS = True
# CELERY_ALWAYS_EAGER=False

CELERYD_LOG_LEVEL = "INFO"
#CELERY_REDIRECT_STDOUTS_LEVEL="DEBUG"

CELERYD_CONCURRENCY = 8
# CELERY_IGNORE_RESULT

# CELERY_TRACK_STARTED =True
#
CELERY_SEND_TASK_SENT_EVENT = True

CELERY_SEND_EVENTS = True

CELERY_RESULT_BACKEND = 'rpc'

# CELERY_ACCEPT_CONTENT = ['json']
# CELERY_TASK_SERIALIZER = 'json'
# CELERY_RESULT_SERIALIZER = 'json'
# from kombu import serialization
# serialization.registry._decoders.pop("application/x-python-serialize")
CELERY_IGNORE_RESULT = False  # this is less important

CELERY_QUEUES = (Queue('celery', Exchange('celery'), routing_key='celery'), )
#
#
#
# #
# # CELERY_QUEUES = ( Queue('default', Exchange('default'), routing_key='default'),
# # )
コード例 #8
0
# of such consortium member educational agencies.
'''
Created on Mar 27, 2014

@author: tosako
'''
from edmigrate.utils.utils import Singleton, get_broker_url
from edmigrate.tasks.player import Player
from kombu import Connection
from edmigrate.queues import conductor
from edmigrate.utils.constants import Constants
from edmigrate.utils import reply_to_conductor
import unittest
from kombu.entity import Exchange, Queue

exchange = Exchange('test', type='direct')
queue = Queue('test',
              exchange=exchange,
              routing_key='test.test',
              durable=False)


class Unittest_with_player(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        mock = MockPlayer()
        Player._instances[Player] = mock

    @classmethod
    def tearDownClass(cls):
        Player._instances.clear()
コード例 #9
0
ファイル: producer02.py プロジェクト: williamsyb/mycookbook
# @Email   : [email protected]
# @File    : producer02.py
# @Software: PyCharm

import time
from kombu.entity import Exchange, Queue
from kombu.messaging import Producer
from kombu.connection import Connection

with Connection(
        'amqp://*****:*****@10.46.0.39:5672/rapid_alpha_dev') as connection:
    with connection.channel() as channel:
        for i in range(1, 10):
            science_news = Queue(
                name='kombu_queue',
                exchange=Exchange('kombu_queue', type='direct'),
                routing_key='kombu_queue',
                channel=channel,
                durable=False,
            )
            science_news.declare()
            producer = Producer(channel,
                                serializer='json',
                                routing_key='kombu_queue')
            producer.publish({'name': 'kombu_queue', 'size': i})

            science_news = Queue(
                name='kombu_queue_1',
                exchange=Exchange('kombu_queue_1', type='direct'),
                routing_key='kombu_queue_1',
                channel=channel,
コード例 #10
0
 def test_publish(self):
     chan = get_conn().channel()
     Exchange('foo', channel=chan).publish('the quick brown fox')
     self.assertIn('basic_publish', chan)
コード例 #11
0
 def test_delete(self):
     chan = get_conn().channel()
     Exchange('foo', channel=chan).delete()
     self.assertIn('exchange_delete', chan)
コード例 #12
0
 def test_create_message(self):
     chan = get_conn().channel()
     Exchange('foo', channel=chan).Message({'foo': 'bar'})
     self.assertIn('prepare_message', chan)
コード例 #13
0
 def test_set_persistent_delivery_mode(self):
     exc = Exchange('foo', 'direct', delivery_mode='persistent')
     self.assertEqual(exc.delivery_mode, Exchange.PERSISTENT_DELIVERY_MODE)
コード例 #14
0
 def test_set_transient_delivery_mode(self):
     exc = Exchange('foo', 'direct', delivery_mode='transient')
     self.assertEqual(exc.delivery_mode, Exchange.TRANSIENT_DELIVERY_MODE)
コード例 #15
0
 def initialize(self):
     super(ActionTask, self).initialize()
     self.exchange = Exchange('xaction', type='direct')
     self._inner_logger = ProxyLogger(self.logger)
コード例 #16
0
ファイル: mqutils.py プロジェクト: liruidesysu/cloudCluster
def delete_queue(name):
    exchange = Exchange('agent', type='topic')
    queue = Queue(name, exchange=exchange, routing_key='news')
    q = queue(channel)
    q.delete(nowait=True)
コード例 #17
0
 def test_publish_with_Exchange_instance(self):
     p = self.connection.Producer()
     p.exchange.publish = Mock()
     p.publish("hello", exchange=Exchange("foo"))
     self.assertEqual(p.exchange.publish.call_args[0][4], "foo")
コード例 #18
0
ファイル: pidbox.py プロジェクト: mozilla/webifyme-lib
 def _get_reply_exchange(self, namespace):
     return Exchange(self.reply_exchange_fmt % namespace,
                     type="direct",
                     durable=False,
                     auto_delete=True,
                     delivery_mode="transient")
コード例 #19
0
# tasks.add will go with the queue: tasks_queue for both producer and consumer
CELERY_ROUTES = {
    'tasks.add': {
        'queue': 'tasks_queue',
        'routing_key': 'tasks_routing'
    },
    'tasks.mul': {
        'queue': 'tasks_queue',
        'routing_key': 'tasks_routing'
    },
    #'tasks.add_1': {'queue': 'tasks_queue', 'routing_key': 'tasks_routing_1'},
    #'tasks.add_2': {'queue': 'tasks_queue_2', 'routing_key': 'tasks_routing_2'},
}

# define exchanges explicitly, change type here requires reset queue/exchange: 'celery amqp queue.delete tasks_queue' and 'celery amqp exchange.delete tasks_exchange'
tasks_exchange = Exchange('tasks_exchange',
                          type='direct')  # fanout/direct/topic

# For tasks.py to listen the queue: tasks_queue
CELERY_QUEUES = (
    Queue('tasks_queue', tasks_exchange, routing_key='tasks_routing'),
    # Queue('tasks_queue', tasks_exchange, routing_key='tasks_routing_1'),
    # Queue('tasks_queue_2', tasks_exchange, routing_key='tasks_routing_2'),
    # routing_key could be 'tasks.#', '*.tasks.*' if exchange type is 'topic'
)

# acknowledged after the task has been executed, False by default
CELERY_ACKS_LATE = True

# The worker will reserve at most one extra task for every active worker process.
# CELERYD_PREFETCH_MULTIPLIER = 1
#
コード例 #20
0
 def setUp(self):
     self.connection = BrokerConnection(transport=Transport)
     self.exchange = Exchange("test_Redis", type="direct")
     self.queue = Queue("test_Redis", self.exchange, "test_Redis")
コード例 #21
0
 def test__repr__(self):
     b = Exchange("foo", "topic")
     self.assertIn("foo(topic)", repr(b))
     self.assertIn("Exchange", repr(b))
コード例 #22
0
# -*- encoding: utf-8 -*-
'''
Created on 2016年9月9日

@author: huawei
'''
from celery.app.base import Celery
from kombu.entity import Exchange,Queue

test ="amqp://*****:*****@172.16.4.134:5672/cabbage_vhost"
app = Celery('cabbage',backend="rpc://",broker=test)

CELERY_QUEUES = ( Queue('mac', Exchange('mac'), routing_key='mac'),)
# 
# 
CELERY_ROUTES ={ u'test_both_task.TestBoth': {'queue': 'both', 'routing_key': 'both'}, u'test_mac_task.TestMacTask': {'queue': 'mac', 'routing_key': 'mac'}, u'test_ubuntu_task.TestUbuntuTask': {'queue': 'ubuntu', 'routing_key': 'ubuntu'}}
#  
app.conf.update(CELERY_QUEUES=CELERY_QUEUES)
app.conf.update(CELERY_ROUTES=CELERY_ROUTES)
app.conf.update(CELERY_SEND_TASK_SENT_EVENT=True,CELERY_SEND_EVENTS=True)

def my_monitor(app):
    state = app.events.State()
    
    def announce_failed_tasks(event):
        print "monitor"
#         print state.alive_workers()
        state.event(event)
        # task name is sent only with -received event, and state
        # will keep track of this for us.
        if 'uuid' in event:
コード例 #23
0
 def test_hash(self):
     self.assertEqual(hash(Exchange("a")), hash(Exchange("a")))
     self.assertNotEqual(hash(Exchange("a")), hash(Exchange("b")))
コード例 #24
0
# -*- coding: utf-8 -*-
"""Worker name utilities."""
from __future__ import absolute_import, unicode_literals
import os
import socket
from functools import partial
from kombu.entity import Exchange, Queue
from .functional import memoize
from .text import simple_format

#: Exchange for worker direct queues.
WORKER_DIRECT_EXCHANGE = Exchange('C.dq2')

#: Format for worker direct queue names.
WORKER_DIRECT_QUEUE_FORMAT = '{hostname}.dq2'

#: Separator for worker node name and hostname.
NODENAME_SEP = '@'

NODENAME_DEFAULT = 'celery'

gethostname = memoize(1, Cache=dict)(socket.gethostname)

__all__ = [
    'worker_direct',
    'gethostname',
    'nodename',
    'anon_nodename',
    'nodesplit',
    'default_nodename',
    'node_format',
コード例 #25
0
 def test_set_transient_delivery_mode(self):
     exc = Exchange("foo", "direct", delivery_mode="transient")
     self.assertEqual(exc.delivery_mode, Exchange.TRANSIENT_DELIVERY_MODE)
コード例 #26
0
import time
import socket
import threading

from collections import deque
from contextlib import contextmanager
from itertools import count

from kombu.entity import Exchange, Queue
from kombu.messaging import Consumer, Producer

from ..app import app_or_default
from ..utils import uuid

event_exchange = Exchange("celeryev", type="topic")


def Event(type, _fields=None, **fields):
    """Create an event.

    An event is a dictionary, the only required field is ``type``.

    """
    event = dict(_fields or {}, type=type, **fields)
    if "timestamp" not in event:
        event["timestamp"] = time.time()
    return event


class EventDispatcher(object):
コード例 #27
0
 def test_bind_at_instantiation(self):
     self.assertTrue(Exchange("foo", channel=get_conn().channel()).is_bound)
コード例 #28
0
 def test_delete(self):
     chan = get_conn().channel()
     Exchange("foo", channel=chan).delete()
     self.assertIn("exchange_delete", chan)
コード例 #29
0
 def test_publish(self):
     chan = get_conn().channel()
     Exchange("foo", channel=chan).publish("the quick brown fox")
     self.assertIn("basic_publish", chan)
コード例 #30
0
 def setUp(self):
     self.exchange = Exchange('foo', 'direct')