Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
coolamqp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
coolamqp
Commits
91d60d5c
Commit
91d60d5c
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
moar docs
parent
441ecc70
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/index.rst
+0
-5
0 additions, 5 deletions
docs/index.rst
docs/tutorial.md
+40
-1
40 additions, 1 deletion
docs/tutorial.md
with
40 additions
and
6 deletions
docs/index.rst
+
0
−
5
View file @
91d60d5c
.. CoolAMQP documentation master file, created by
sphinx-quickstart on Sat Jan 28 16:24:42 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to CoolAMQP's documentation!
Welcome to CoolAMQP's documentation!
====================================
====================================
...
...
This diff is collapsed.
Click to expand it.
docs/tutorial.md
+
40
−
1
View file @
91d60d5c
...
@@ -25,4 +25,43 @@ cluster = Cluster([node])
...
@@ -25,4 +25,43 @@ cluster = Cluster([node])
cluster
.
start
(
wait
=
True
)
cluster
.
start
(
wait
=
True
)
```
```
_wait=True_
will block until connection is completed. After this, you can use other methods.
_wait=True_
will block until connection is completed. After this, you can use other methods.
\ No newline at end of file
## Publishing and consuming
Connecting is boring. After we do, we want to do something! Let's try sending a message, and receiving it. To do that,
you must first define a queue, and register a consumer.
```
python
from
coolamqp.objects
import
Queue
queue
=
Queue
(
u
'
my_queue
'
,
auto_delete
=
True
,
exclusive
=
True
)
consumer
,
consume_confirm
=
cluster
.
consume
(
queue
,
no_ack
=
False
)
consume_confirm
.
result
()
# wait for consuming to start
```
This will create an auto-delete and exclusive queue. After than, a consumer will be registered for this queue.
_no_
ack=False_ will mean that we have to manually confirm messages.
You can specify a callback, that will be called with a message if one's received by this consumer. Since
we did not do that, this will go to a generic queue belonging to _Cluster_.
_consumer_
is a _Consumer_ object. This allows us to do some things with the consumer (such as setting QoS),
but most importantly it allows us to cancel it later. _consume_confirm_ is a _Future_, that will succeed
when AMQP _basic.consume-ok_ is received.
To send a message we need to construct it first, and later publish:
```
python
from
coolamqp.objects
import
Message
msg
=
Message
(
b
'
hello world
'
,
properties
=
Message
.
Properties
())
cluster
.
publish
(
msg
,
routing_key
=
u
'
my_queue
'
)
```
This creates a message with no properties, and sends it through default (direct) exchange to our queue.
Note that CoolAMQP simply considers your messages to be bags of bytes + properties. It will not modify them,
nor decode, and will always expect and return bytes.
To actually get our message ...
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment