File: README.rst

package info (click to toggle)
python-pika-pool 0.1.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 92 kB
  • sloc: python: 384; makefile: 12; sh: 5
file content (87 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
=========
pika-pool
=========

.. image:: https://travis-ci.org/bninja/pika-pool.png
   :target: https://travis-ci.org/bninja/pika-pool
   
.. image:: https://coveralls.io/repos/bninja/pika-pool/badge.png?branch=master
   :target: https://coveralls.io/r/bninja/pika-pool?branch=master

Pika connection pooling inspired by:

- `flask-pika <https://github.com/WeatherDecisionTechnologies/flask-pika>`_
- `sqlalchemy.pool.Pool <http://docs.sqlalchemy.org/en/latest/core/pooling.html#sqlalchemy.pool.Pool>`_

Typically you'll go with local `shovels <https://www.rabbitmq.com/shovel.html>`_, `krazee-eyez kombu <http://bit.ly/1txcnnO>`_, etc. but this works too.

usage
-----

Get it:

.. code:: bash

   pip install pika-pool

and use it:

.. code:: python

   import json

   import pika
   import pika_pool

   params = pika.URLParameters(
      'amqp://guest:guest@localhost:5672/?'
      'socket_timeout=10&'
      'connection_attempts=2'
    )

    pool = pika_pool.QueuedPool(
        create=lambda: pika.BlockingConnection(parameters=params),
        max_size=10,
        max_overflow=10,
        timeout=10,
        recycle=3600,
        stale=45,
    )

    with pool.acquire() as cxn:
        cxn.channel.basic_publish(
            body=json.dumps({
                'type': 'banana',
                'description': 'they are yellow'
            }),
            exchange='',
            routing_key='fruits',
            properties=pika.BasicProperties(
                content_type='application/json',
                content_encoding='utf-8',
                delivery_mode=2,
            )
        )

release
-------

Tests pass:

.. code:: bash

   py.test test.py --cov=pika_pool --cov-report term-missing

so update ``__version__`` in:

- ``__init__.py``

then commit and tag it:

.. code:: bash

   git commit -am "release v{version}"
   git tag -a v{version} -m "release v{version}"
   git push --tags

and `travis <https://travis-ci.org/bninja/pika-pool>`_ will publish it to `pypi <https://pypi.python.org/pypi/pika-pool/>`_.