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
fb857f4e8959
Commit
fb857f4e8959
authored
7 years ago
by
Luke Bakken
Browse files
Options
Downloads
Patches
Plain Diff
Use ack_message from README
parent
e0c244dd32b7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/basic_consumer_threaded.py
+13
-8
13 additions, 8 deletions
examples/basic_consumer_threaded.py
with
13 additions
and
8 deletions
examples/basic_consumer_threaded.py
+
13
−
8
View file @
fb857f4e
...
...
@@ -10,9 +10,20 @@
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
LOG_FORMAT
)
def
ack_message
(
channel
,
delivery_tag
):
"""
Note that `channel` must be the same pika channel instance via which
the message being ACKed was retrieved (AMQP protocol constraint).
"""
if
channel
.
is_open
:
channel
.
basic_ack
(
delivery_tag
)
else
:
# Channel is already closed, so we can't ACK this message;
# log and/or do something that makes sense for your app in this case.
pass
def
do_work
(
connection
,
channel
,
delivery_tag
,
body
):
thread_id
=
threading
.
get_ident
()
fmt1
=
'
Thread id: {} Delivery tag: {} Message body: {}
'
LOGGER
.
info
(
fmt1
.
format
(
thread_id
,
delivery_tag
,
body
))
# Sleeping to simulate 10 seconds of work
time
.
sleep
(
10
)
...
...
@@ -13,11 +24,8 @@
def
do_work
(
connection
,
channel
,
delivery_tag
,
body
):
thread_id
=
threading
.
get_ident
()
fmt1
=
'
Thread id: {} Delivery tag: {} Message body: {}
'
LOGGER
.
info
(
fmt1
.
format
(
thread_id
,
delivery_tag
,
body
))
# Sleeping to simulate 10 seconds of work
time
.
sleep
(
10
)
if
channel
.
is_open
:
fmt2
=
'
Thread id: {} Delivery tag: {} sending ack
'
LOGGER
.
info
(
fmt2
.
format
(
thread_id
,
delivery_tag
))
cb
=
functools
.
partial
(
channel
.
basic_ack
,
delivery_tag
)
cb
=
functools
.
partial
(
ack_message
,
channel
,
delivery_tag
)
connection
.
add_callback_threadsafe
(
cb
)
...
...
@@ -23,7 +31,4 @@
connection
.
add_callback_threadsafe
(
cb
)
else
:
fmt2
=
'
Thread id: {} Delivery tag: {} not sending ack, channel closed
'
LOGGER
.
info
(
fmt2
.
format
(
thread_id
,
delivery_tag
))
def
on_message
(
channel
,
method_frame
,
header_frame
,
body
,
args
):
(
connection
,
threads
)
=
args
...
...
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