Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update asynqp to v0.4 #1

Open
wants to merge 146 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
11be993
Merge pull request #13 from renatomassaro/master
Mar 27, 2015
52d5232
I do everything flake8 tells me
May 6, 2015
ab3de4a
add gitattributes and fix up line endings
May 6, 2015
4d9cfef
Update ez_setup
May 6, 2015
0795309
Update CONTRIBUTING.md
May 11, 2015
7bf3673
Run flake8 on travis
May 12, 2015
8827818
do not pass host and port to loop.create_connection when there's a so…
urbaniak May 6, 2015
50cd0e7
add integration test for pull request #14 from @urbaniak
May 12, 2015
b6441a9
__all__
May 12, 2015
067c651
Expose transport and protocol on Connection
May 12, 2015
c848bf3
address #12 by allowing properties to be set with setattr
May 12, 2015
c8d46e8
improve docs of Message
May 12, 2015
ca15931
fix __all__
May 14, 2015
8d0e45f
Copy fix from readme into docs front page
May 18, 2015
f665308
Added new exceptions and logic to allow for designing programs that
lenzenmi May 18, 2015
eb78250
Example script
lenzenmi May 19, 2015
4296074
Comment updates
lenzenmi May 20, 2015
2572719
Merge pull request #19 from lenzenmi/bug/lost-connection-exception
May 23, 2015
9baf3a8
Merge pull request #20 from lenzenmi/example/reconnecting-socket
May 23, 2015
e410050
Stop squashing OsError into ConnectionRefusedError when connecting
lenzenmi May 24, 2015
30e7cf0
Merge pull request #21 from lenzenmi/revert/stop_squashing_exception
May 25, 2015
7dbfa33
Fix #22 by killing futures when ChannelClose arrives
Jun 2, 2015
c2be32b
Signed/unsigned serialization and expanded table serialization
fwiesel Jun 3, 2015
85cd89f
Fix formatting
fwiesel Jun 4, 2015
5dc2ed1
Merge pull request #24 from fwiesel/serialization_fixes
Jun 4, 2015
3dd0d57
Update date
Jun 4, 2015
130a85f
Table length should be unsigned long
fwiesel Jun 6, 2015
c0ff4d9
Implement timestamp serialisation
fwiesel Jun 6, 2015
397f979
Fixed formatting for tests
fwiesel Jun 6, 2015
f2d2d43
Fix typo in test description
fwiesel Jun 6, 2015
44bfcf5
Fix internal timestamp representation to utc
fwiesel Jun 7, 2015
e7303a8
Rename time_stamp to timestamp, following the style in datetime
fwiesel Jun 7, 2015
735be64
Table length should be unsigned long
fwiesel Jun 6, 2015
5fa7cfc
Merge pull request #28 from fwiesel/unsigned_table_length
Jun 11, 2015
a15a2c0
Merge pull request #25 from fwiesel/timestamp
Jun 11, 2015
73123ed
Changed serialisation to Qpid/RabbitMq codes, added more types
fwiesel Jun 6, 2015
611d2fe
Changed serialisation to Qpid/RabbitMq codes, added more types
fwiesel Jun 6, 2015
7102f5a
Merge pull request #26 from fwiesel/rabbitmq_compatibility
Jun 11, 2015
7532646
Pass table arguments to broker
fwiesel Jun 10, 2015
a198572
Merge pull request #27 from fwiesel/rabbitmq_extensions
Jun 12, 2015
3762023
trial import of setuptools
Jun 14, 2015
c31da9c
Documentation; minor API fixes
Jun 14, 2015
aa20708
Add examples to docs
Jun 14, 2015
93d3703
Fixed a test on my windows machine.
Jun 30, 2015
08b6930
#23 throw more specific exceptions
Jun 30, 2015
7c5c06f
add exception docs and made function private
Jun 30, 2015
1536ac0
fix __all__
Jun 30, 2015
3e6ce99
Increment version to 0.4
Jun 30, 2015
9254ae6
#31 remove ConnectionClosedError
Jul 8, 2015
7a8972f
refactoring around closing connections
Jul 8, 2015
c0f88bf
Update README.md
Jul 8, 2015
c93690f
#31 Add Connection.closed future (which was documented but did not ex…
Jul 8, 2015
3fd2024
Upgrade to new, faster Travis infrastructure
Jul 26, 2015
b5374dd
fix badge
Jul 26, 2015
728dc9f
Update .travis.yml
Aug 24, 2015
3a23f71
Create requirements.txt
Sep 4, 2015
7be7797
Update .travis.yml
Sep 4, 2015
7057da2
Update README.md
Sep 4, 2015
df5aacd
coveralls
Sep 4, 2015
df64005
woops
Sep 4, 2015
5800107
coverage
Sep 4, 2015
d3ead47
Fix #37. You should be able to open multiple channels concurrently
Sep 15, 2015
e30c0fd
#34 build API for handling failures in a consumer
Sep 15, 2015
10ce858
Fix #32
Sep 15, 2015
c9d76b4
test on python 3.5
Sep 15, 2015
82815f7
setup.py 3.5
Sep 16, 2015
28b0b59
fix #39 (docs were wrong)
Sep 17, 2015
b509f10
Added explicit loop passing to all componencts from connection.
taras-doba-ua Sep 19, 2015
ea1fe9d
Removed unused optional asyncion.get_event_loop calls
taras-doba-ua Sep 19, 2015
784de0b
And another unused get_event_loop call
taras-doba-ua Sep 19, 2015
5522c22
Removed unneded local `_loop` veriable in Connection
taras-doba-ua Sep 20, 2015
d54d0e9
Merge pull request #42 from TarasLevelUp/master
Sep 21, 2015
4bb6999
Added some tests on unset loop
taras-doba-ua Sep 21, 2015
aacc97d
Merge pull request #43 from TarasLevelUp/master
Sep 21, 2015
e9aa720
Some tests were passing when they shouldn't.
Sep 21, 2015
72d103f
Fix #45: HeartbeatMonitor now controls two tasks, not a chain of call…
Sep 21, 2015
3b93de3
#45 delete obsolete tests
Sep 21, 2015
189e11d
keep flake8 happy
Sep 21, 2015
15307f9
Fixed great number of tracebacks in tests for not closed heartbeat.
taras-doba-ua Sep 22, 2015
bdf9402
Fix flake8
taras-doba-ua Sep 22, 2015
2ffa802
Minor fix to heartbeat
taras-doba-ua Sep 23, 2015
29b3990
Fixed connection test to wait a bit before checking
taras-doba-ua Sep 23, 2015
5108f2b
Merge pull request #46 from TarasLevelUp/fix_heartbeat
Sep 23, 2015
02d9ddf
Fix connection close after graceful close from server
taras-doba-ua Sep 12, 2015
4438367
Log warning if called `close` on already closed connection
taras-doba-ua Sep 21, 2015
6ba3630
Merge pull request #36 from TarasLevelUp/fix_connection_close
Sep 23, 2015
ad14f65
Fix #40 set TCP_NODELAY by default
socketpair Sep 19, 2015
fbef52f
Merge pull request #41 from socketpair/nodelay
Sep 29, 2015
baa6342
Refactored reader to not use async calls
taras-doba-ua Oct 4, 2015
274cdbc
Refactor message_receiver to not use async tasks on message consuming
taras-doba-ua Oct 4, 2015
33afaa5
Removed `callback` from message_receiver. Let `receive_body` decide h…
taras-doba-ua Oct 5, 2015
4c24984
Removed QueueWriter and passing Reader instead. Renamed QueueReader t…
taras-doba-ua Oct 5, 2015
b7f99c8
Flake8 and spelling fix
taras-doba-ua Oct 5, 2015
ee44fe5
Merge pull request #48 from TarasLevelUp/refactor_reader2
Oct 5, 2015
f396222
Merge pull request #50 from TarasLevelUp/refactor_message_receiver
Oct 5, 2015
50ba10a
Refactored Synchroniser to not use strage constructs based on Ordered…
taras-doba-ua Oct 4, 2015
bf2a93b
Changed how awaiting multiple methods are handled
taras-doba-ua Oct 5, 2015
1e99adf
Merge pull request #49 from TarasLevelUp/refactor_syncronizer
Oct 16, 2015
78ad162
Changed how protocol handles connection_lost. Don't dispatch PoisonPill
taras-doba-ua Oct 17, 2015
145819d
Merge pull request #54 from TarasLevelUp/protocol_close
Oct 21, 2015
a3cb168
Fix #57 Components not killed when rabbit just closes transport
tvoinarovskyi Oct 31, 2015
78fac49
Added passive argument to declare_queue
tvoinarovskyi Nov 2, 2015
34ec8c6
Added passive argument to declare exchange
tvoinarovskyi Nov 2, 2015
9054fe0
Added docs for passive arguments
tvoinarovskyi Nov 2, 2015
3e3c72f
Merge pull request #59 from TarasLevelUp/fix_57
Nov 3, 2015
95551f7
fix #58 by raising AlreadyClosed from the connection
Nov 3, 2015
5fbde91
mute log in tests
Nov 3, 2015
abd7245
Little cleanup for passive argument tests.
tvoinarovskyi Nov 3, 2015
4bf0470
Refactor close procedure of Connection, Channel and Consumer to raise…
taras-doba-ua Sep 30, 2015
0198687
Cleaned up and fixed tests
tvoinarovskyi Nov 3, 2015
f4c2743
Renamed exceptions, got rid of ClientConnectionError and ServerConnec…
tvoinarovskyi Nov 3, 2015
98d1d2b
Merge pull request #55 from TarasLevelUp/reader_refactor
Nov 28, 2015
c0168af
Merge pull request #61 from TarasLevelUp/passive_declare
Nov 28, 2015
7df87b7
Added nowait parameters to queue and exchange declarations
tvoinarovskyi Dec 2, 2015
6191d88
Merge pull request #63 from TarasLevelUp/nowait_support
Dec 3, 2015
8f55f2f
ignore pep8 W503
benjamin-hodgson Mar 11, 2016
cab97e9
Added server side consumer cancel
tvoinarovskyi Nov 1, 2015
036e107
Fix flake errors
tvoinarovskyi Nov 1, 2015
13b7c11
Fixed amqp properties reading. Had invalid flag checks.
tvoinarovskyi Dec 7, 2015
5bc9ce3
Added test for reading content properties with some missing bits
tvoinarovskyi Mar 8, 2016
142d98e
Tiny timing increase so tests pass on travis
tvoinarovskyi Mar 8, 2016
45e8619
Added v0.5 changes and fixed conformance doc page
tvoinarovskyi Mar 20, 2016
f824740
Added backward compatible closed future.
tvoinarovskyi Mar 20, 2016
ec31220
Changed the reconnect example to show new features in 0.5
tvoinarovskyi Mar 20, 2016
c0b1ea1
Correctly handle zero-length messages
anton-ryzhov Mar 20, 2016
b77ad90
Unittest
tvoinarovskyi Mar 21, 2016
8df2c6b
Merge pull request #76 from anton-ryzhov/empty_messages
benjamin-hodgson May 1, 2016
f2b1adf
Merge pull request #60 from TarasLevelUp/server_side_consumer_cancel
benjamin-hodgson May 1, 2016
33100d5
Merge pull request #66 from TarasLevelUp/protocol_fix
benjamin-hodgson May 1, 2016
2d2eca9
Merge pull request #72 from TarasLevelUp/v0.5_release_doc
benjamin-hodgson May 1, 2016
aae940a
Merge pull request #75 from TarasLevelUp/new_reconnect_example
benjamin-hodgson May 1, 2016
0b40144
Merge pull request #74 from TarasLevelUp/return_close_fut
benjamin-hodgson May 1, 2016
6204715
Bump version to 0.5
Jun 29, 2016
8e298e1
>:( flake8 bug
Jun 29, 2016
fddabe8
bump again
Jun 29, 2016
59e839f
Throw when binding to an invalid exchange
Jun 29, 2016
9d1b300
Changed all occurences of 'try except pass' into 'with suppress' cont…
purpleP Aug 12, 2016
2fe7109
Mark amq.rabbitmq.reply-to as valid queue name (#86)
cybergrind Aug 30, 2016
992c356
Add simple on_connection_close handler without exception handlers (#88)
polosaty Oct 20, 2016
6d05656
Doc mandatory param; cross link to set_return_handler (#93)
bitdancer Feb 6, 2017
53d9724
fix asyncio.async deprecation warning (replaced with ensure_future) (…
romantolkachyov Sep 8, 2017
6294536
Add support for Python up to 3.7. (#104)
evmyzgin Aug 21, 2018
014a897
Update .travis.yml
Jan 20, 2019
858249e
Update .travis.yml
Jan 20, 2019
ce7ec39
Update .travis.yml
Jan 20, 2019
ea8630d
increment version to 0.6
Jan 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
113 changes: 57 additions & 56 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
doc/_build/

*.sublime-workspace
.ipynb_checkpoints
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
doc/_build/

*.sublime-workspace
.ipynb_checkpoints
.DS_Store
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
sudo: false

language: python

python: 3.4
python:
- 3.4
- 3.5
- 3.6

services: rabbitmq

install:
- pip install contexts colorama sphinx
- python setup.py install
- pip install -r requirements.txt
- python setup.py develop

script:
- run-contexts -v
- cd doc && make html
- flake8 src test --ignore=E501,W503,E722
- coverage run --source=src -m contexts -v
- pushd doc && make html && popd

after_success:
coveralls

deploy:
provider: pypi
Expand All @@ -21,6 +30,3 @@ deploy:
tags: true
all_branches: true
distributions: "sdist bdist_wheel bdist_egg"

after_deploy:
- curl -X POST http://readthedocs.org/build/asynqp
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
What's new in `asynqp`
======================


v0.5
----
* Channels will no longer break if their calls are cancelled. Issue #52.
* Fixed message properties decoding without `content_type`. Pull request #66.
* Added `nowait` argument to Exchange and Queue declarations.
* Added `passive` argument to Exchange and Queue declarations.
* Added `on_error` and `on_cancel` callbacks for Consumer. Issue #34
* Changed the closing scheme for Channel/Connection. Proper exceptions are now
always propagated to user. Issues #57, #58
* Complete internals refactor and cleanup. Rull requests #48, #49, #50.
* Add NO_DELAY option for socket. Issue #40. (Thanks to @socketpair for PR #41)
* Change heartbeat to be a proper background task. Issue #45.
* `loop` is now proparly passed to all components from open_connection call. Pull request #42.
* Add support for Python up to 3.5.

v0.4
----

* Improved error handling.
* When the connection to the server is lost, any futures awaiting communication
from the server will now be cancelled.
(Thanks to @lenzenmi, in pull request #19)
* More detailed exceptions on channel closure.
* Support for custom RabbitMQ extensions by an `arguments` keyword parameter for a number of methods.
(Thanks to @fweisel, in pull request #27)
* Improved compatibility with RabbitMQ's implementation of the
wire protocol, including better support for tables.
(Thanks to @fweisel, in pull requests #24, #25, #26, #28)
* Support for a `sock` keyword argument to `asynqp.connect`.
(Thanks to @urbaniak, in pull request #14)

4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ To contribute to this project, submit a [pull request](https://help.github.com/a
3. [Open a pull request](https://help.github.com/articles/creating-a-pull-request) in this repo to merge your topic branch into the mainstream
4. I'll review your changes and merge your pull request as soon as possible

If you want to contribute to the project, but are not sure what you want to work on,
I am always happy for help on any of the [open issues](https://github.com/benjamin-hodgson/asynqp/issues)
in the GitHub tracker.

This project is built using Test-Driven-Development.
So if you're planning to contribute a feature or bugfix, please **ensure that
it is covered by tests** before submitting it for review. Use your best judgment to
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2014 Benjamin Hodgson
Copyright (c) 2013-2015 Benjamin Hodgson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ asynqp
======

[![Build Status](https://travis-ci.org/benjamin-hodgson/asynqp.svg?branch=master)](https://travis-ci.org/benjamin-hodgson/asynqp)
[![Documentation Status](https://readthedocs.org/projects/asynqp/badge/?version=v0.3)](https://readthedocs.org/projects/asynqp/?badge=v0.3)
[![Documentation Status](https://readthedocs.org/projects/asynqp/badge/?version=v0.4)](https://readthedocs.org/projects/asynqp/?badge=v0.4)
[![Coverage Status](https://coveralls.io/repos/benjamin-hodgson/asynqp/badge.svg?branch=master&service=github)](https://coveralls.io/github/benjamin-hodgson/asynqp?branch=master)
[![Requirements Status](https://requires.io/github/benjamin-hodgson/asynqp/requirements.svg?branch=master)](https://requires.io/github/benjamin-hodgson/asynqp/requirements/?branch=master)

`asynqp` is an AMQP (aka [RabbitMQ](rabbitmq.com)) client library for
Python 3.4's new [`asyncio`](https://docs.python.org/3.4/library/asyncio.html) module.
Expand All @@ -19,7 +21,10 @@ import asynqp


@asyncio.coroutine
def send_and_receive():
def hello_world():
"""
Sends a 'hello world' message and then reads it from the queue.
"""
# connect to the RabbitMQ broker
connection = yield from asynqp.connect('localhost', 5672, username='guest', password='guest')

Expand All @@ -34,7 +39,7 @@ def send_and_receive():
yield from queue.bind(exchange, 'routing.key')

# If you pass in a dict it will be automatically converted to JSON
msg = asynqp.Message({'test_body': 'content'})
msg = asynqp.Message({'hello': 'world'})
exchange.publish(msg, 'routing.key')

# Synchronously get a message from the queue
Expand All @@ -50,7 +55,7 @@ def send_and_receive():

if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(send_and_receive())
loop.run_until_complete(hello_world())
```


Expand Down
16 changes: 8 additions & 8 deletions RELEASING
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1. Check Travis is green on the latest commit
2. Increment the version in setup.py
3. Increment the version in doc/conf.py
4. Commit and tag
5. Push using --follow-tags
6. Check that the tests passed on Travis and it published to the Cheese Shop
6a. If it failed to publish to the cheese shop for some reason, run `python setup.py register` followed by `python setup.py sdist bdist_egg bdist_wheel upload`
7. Build the docs at readthedocs.org and increment the latest version
1. Check Travis is green on the latest commit
2. Increment the version in setup.py
3. Increment the version in doc/conf.py
4. Commit and tag
5. Push using --follow-tags
6. Check that the tests passed on Travis and it published to the Cheese Shop
6a. If it failed to publish to the cheese shop for some reason, run `python setup.py register` followed by `python setup.py sdist bdist_egg bdist_wheel upload`
7. Build the docs at readthedocs.org and increment the latest version
3 changes: 1 addition & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
API design issues

Public implementation-related fields in public classes (even though they're not documented)
Threading issues
Threading issues?
Load testing?


Expand Down Expand Up @@ -41,6 +41,5 @@ Unimplemented methods:
Unimplemented functions

Customise connection-tune response
General exception handling
Passive declares
No-wait flags
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@

# General information about the project.
project = 'asynqp'
copyright = '2014, Benjamin Hodgson'
copyright = '2014-2015, Benjamin Hodgson'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.3'
version = '0.6'
# The full version, including alpha/beta/rc tags.
release = '0.3'
release = '0.6'


def hide_class_constructor(app, what, name, obj, options, signature, return_annotation):
Expand Down
4 changes: 2 additions & 2 deletions doc/conformance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ that are currently supported by ``asynqp``.
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| exchange | | :orange:`partial` | :class:`asynqp.Exchange` | |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| | declare/declare-ok | :orange:`partial` | :meth:`asynqp.Channel.declare_exchange` | Not all parameters presently supported |
| | declare/declare-ok | :green:`full` | :meth:`asynqp.Channel.declare_exchange` | |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| | delete/delete-ok | :green:`full` | :meth:`asynqp.Exchange.delete` | |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
Expand All @@ -56,7 +56,7 @@ that are currently supported by ``asynqp``.
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| queue | | :orange:`partial` | :class:`asynqp.Queue` | |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| | declare/declare-ok | :orange:`partial` | :meth:`asynqp.Channel.declare_queue` | Not all parameters presently supported |
| | declare/declare-ok | :green:`full` | :meth:`asynqp.Channel.declare_queue` | |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
| | bind/bind-ok | :orange:`partial` | :meth:`asynqp.Queue.bind` | Not all parameters presently supported |
+------------+----------------------+-------------------+-------------------------------------------+-----------------------------------------+
Expand Down
14 changes: 14 additions & 0 deletions doc/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Examples
========


Hello World
-----------
.. literalinclude:: /examples/helloworld.py
:language: python


Reconnecting
------------
.. literalinclude:: /examples/reconnecting.py
:language: python
40 changes: 40 additions & 0 deletions doc/examples/helloworld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import asyncio
import asynqp


@asyncio.coroutine
def hello_world():
"""
Sends a 'hello world' message and then reads it from the queue.
"""
# connect to the RabbitMQ broker
connection = yield from asynqp.connect('localhost', 5672, username='guest', password='guest')

# Open a communications channel
channel = yield from connection.open_channel()

# Create a queue and an exchange on the broker
exchange = yield from channel.declare_exchange('test.exchange', 'direct')
queue = yield from channel.declare_queue('test.queue')

# Bind the queue to the exchange, so the queue will get messages published to the exchange
yield from queue.bind(exchange, 'routing.key')

# If you pass in a dict it will be automatically converted to JSON
msg = asynqp.Message({'hello': 'world'})
exchange.publish(msg, 'routing.key')

# Synchronously get a message from the queue
received_message = yield from queue.get()
print(received_message.json()) # get JSON from incoming messages easily

# Acknowledge a delivered message
received_message.ack()

yield from channel.close()
yield from connection.close()


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(hello_world())
Loading