Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
pika
Commits
6512cd69fdd0
Commit
6512cd69fdd0
authored
7 years ago
by
Luke Bakken
Browse files
Options
Downloads
Patches
Plain Diff
pylint
parent
ea447a26d150
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/consume.py
+29
-18
29 additions, 18 deletions
examples/consume.py
with
29 additions
and
18 deletions
examples/consume.py
+
29
−
18
View file @
6512cd69
"""
Basic message consumer example
"""
import
functools
import
logging
import
pika
...
...
@@ -8,7 +9,8 @@
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
LOG_FORMAT
)
def
on_message
(
channel
,
method_frame
,
header_frame
,
body
,
userdata
=
None
):
LOGGER
.
info
(
'
Userdata: {} Message body: {}
'
.
format
(
userdata
,
body
))
channel
.
basic_ack
(
delivery_tag
=
method_frame
.
delivery_tag
)
def
on_message
(
chan
,
method_frame
,
_header_frame
,
body
,
userdata
=
None
):
"""
Called when a message is received. Log message and ack it.
"""
LOGGER
.
info
(
'
Userdata: %s Message body: %s
'
,
userdata
,
body
)
chan
.
basic_ack
(
delivery_tag
=
method_frame
.
delivery_tag
)
...
...
@@ -14,6 +16,8 @@
def
main
():
"""
Main method.
"""
credentials
=
pika
.
PlainCredentials
(
'
guest
'
,
'
guest
'
)
parameters
=
pika
.
ConnectionParameters
(
'
localhost
'
,
credentials
=
credentials
)
connection
=
pika
.
BlockingConnection
(
parameters
)
channel
=
connection
.
channel
()
...
...
@@ -15,9 +19,13 @@
credentials
=
pika
.
PlainCredentials
(
'
guest
'
,
'
guest
'
)
parameters
=
pika
.
ConnectionParameters
(
'
localhost
'
,
credentials
=
credentials
)
connection
=
pika
.
BlockingConnection
(
parameters
)
channel
=
connection
.
channel
()
channel
.
exchange_declare
(
exchange
=
"
test_exchange
"
,
exchange_type
=
"
direct
"
,
passive
=
False
,
durable
=
True
,
auto_delete
=
False
)
channel
.
exchange_declare
(
exchange
=
"
test_exchange
"
,
exchange_type
=
"
direct
"
,
passive
=
False
,
durable
=
True
,
auto_delete
=
False
)
channel
.
queue_declare
(
queue
=
"
standard
"
,
auto_delete
=
True
)
channel
.
queue_bind
(
queue
=
"
standard
"
,
exchange
=
"
test_exchange
"
,
routing_key
=
"
standard_key
"
)
channel
.
basic_qos
(
prefetch_count
=
1
)
...
...
@@ -31,3 +39,6 @@
channel
.
stop_consuming
()
connection
.
close
()
if
__name__
==
'
__main__
'
:
main
()
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