class SimpleAmqpTestCase(unittest.TestCase):

    def get_init(self):
        self._q = SimpleAmqp(pool=['rabbit1', 'rabbit2'], pooltype='L')
        logging.getLogger('simpleAmqp').setLevel(logging.CRITICAL)
        self._q._connect = mock.MagicMock()
        self._q._close = mock.MagicMock()

    def setUp(self):
        self.get_init()

    def tearDown(self):
        pass

    def test_send(self):
        self._q.send('foo','bar')
        self.assertTrue(self._q._close.called)
        self.assertEqual(self._q._close.call_count,1)
        self._q._connect.assert_called_once_with()

    def test_sendMany(self):
        self._q.sendMany('foo',['bar','bla'])
        self.assertTrue(self._q._close.called)
        self.assertEqual(self._q._close.call_count,1)
        self._q._connect.assert_called_once_with()
Ejemplo n.º 2
0
#!/usr/bin/env python
import pika
import random
import logging

from simpleamqp import SimpleAmqp

# Init logging level
logging.getLogger('simpleAmqp').setLevel(logging.CRITICAL)

# Add handler for debug
logging.getLogger('simpleAmqp').setLevel(logging.INFO)
logging.getLogger('simpleAmqp').addHandler(logging.StreamHandler())

q = SimpleAmqp(pool=['rabbit2', 'rabbit2'], pooltype='L')
try:
    q.send('hello',"My message")
except:
    logging.critical("Send message error")

try:
    messages = ["Many message","Many message2"]
    q.sendMany('hello',messages)
except:
    logging.critical("Send message error")
Ejemplo n.º 3
0
#!/usr/bin/env python
import pika
import logging

from simpleamqp import SimpleAmqp

def mycallback(ch, method, properties, body):
    print "mycallback %s" % body

# Init logging level
logging.getLogger('simpleAmqp').setLevel(logging.CRITICAL)

# Add handler for debug
logging.getLogger('simpleAmqp').setLevel(logging.INFO)
logging.getLogger('simpleAmqp').addHandler(logging.StreamHandler())

q = SimpleAmqp(pool=['rabbit1', 'rabbit2'], pooltype='F')
q._callback = mycallback
try:
    q.recv('hello')
except:
    logging.critical("Recv message error")
 def get_init(self):
     self._q = SimpleAmqp(pool=['rabbit1', 'rabbit2'], pooltype='L')
     logging.getLogger('simpleAmqp').setLevel(logging.CRITICAL)
     self._q._connect = mock.MagicMock()
     self._q._close = mock.MagicMock()