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
ccf40787
Commit
ccf40787
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
yay qos
parent
2e3c4fb6
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
coolamqp/attaches/consumer.py
+28
-2
28 additions, 2 deletions
coolamqp/attaches/consumer.py
tests/run.py
+3
-1
3 additions, 1 deletion
tests/run.py
with
31 additions
and
3 deletions
coolamqp/attaches/consumer.py
+
28
−
2
View file @
ccf40787
...
...
@@ -5,7 +5,7 @@ from coolamqp.framing.frames import AMQPBodyFrame, AMQPHeaderFrame
from
coolamqp.framing.definitions
import
ChannelOpenOk
,
BasicConsume
,
\
BasicConsumeOk
,
QueueDeclare
,
QueueDeclareOk
,
ExchangeDeclare
,
ExchangeDeclareOk
,
\
QueueBind
,
QueueBindOk
,
ChannelClose
,
BasicCancel
,
BasicDeliver
,
\
BasicAck
,
BasicReject
,
ACCESS_REFUSED
,
RESOURCE_LOCKED
,
BasicCancelOk
BasicAck
,
BasicReject
,
ACCESS_REFUSED
,
RESOURCE_LOCKED
,
BasicCancelOk
,
BasicQos
from
coolamqp.uplink
import
HeaderOrBodyWatch
,
MethodWatch
from
coolamqp.attaches.channeler
import
Channeler
,
ST_ONLINE
,
ST_OFFLINE
...
...
@@ -36,6 +36,8 @@ class Consumer(Channeler):
:param queue: Queue object, being consumed from right now.
Note that name of anonymous queue might change at any time!
:param no_ack: Will this consumer require acknowledges from messages?
:param qos: a tuple of (prefetch size, prefetch window) for this consumer
:type qos: tuple(int, int) or tuple(None, int)
:param dont_pause: Consumer will fail on the spot instead of pausing
"""
super
(
Consumer
,
self
).
__init__
()
...
...
@@ -50,6 +52,22 @@ class Consumer(Channeler):
self
.
attache_group
=
None
# attache group this belongs to.
# if this is not None, then it has an attribute
# on_cancel_customer(Consumer instance)
if
qos
is
not
None
:
if
qos
[
0
]
is
None
:
qos
=
0
,
qos
[
1
]
# prefetch_size=0=undefined
self
.
qos
=
qos
self
.
qos_update_sent
=
False
# QoS was not sent to server
def
set_qos
(
self
,
prefetch_size
,
prefetch_count
):
"""
Set new QoS for this consumer.
:param prefetch_size: prefetch in octets
:param prefetch_count: prefetch in whole messages
"""
if
self
.
state
==
ST_ONLINE
:
self
.
method
(
BasicQos
(
prefetch_size
or
0
,
prefetch_count
,
False
))
self
.
qos
=
prefetch_size
or
0
,
prefetch_count
def
cancel
(
self
):
"""
...
...
@@ -109,9 +127,12 @@ class Consumer(Channeler):
if
payload
.
reply_code
in
(
ACCESS_REFUSED
,
RESOURCE_LOCKED
):
should_retry
=
True
# We might not want to throw the connection away.
should_retry
=
should_retry
and
(
not
self
.
cancelled
)
super
(
Consumer
,
self
).
on_close
(
payload
)
should_retry
=
should_retry
and
(
not
self
.
cancelled
)
#todo retry on access denied
...
...
@@ -191,6 +212,8 @@ class Consumer(Channeler):
self
.
on_setup
(
QueueBindOk
())
elif
isinstance
(
payload
,
QueueBindOk
):
# itadakimasu
if
self
.
qos
is
not
None
:
self
.
method
(
BasicQos
(
self
.
qos
[
0
],
self
.
qos
[
1
],
False
))
self
.
method_and_watch
(
BasicConsume
(
self
.
queue
.
name
.
encode
(
'
utf8
'
),
self
.
queue
.
name
.
encode
(
'
utf8
'
),
False
,
self
.
no_ack
,
self
.
queue
.
exclusive
,
False
,
[]),
...
...
@@ -210,6 +233,9 @@ class Consumer(Channeler):
self
.
state
=
ST_ONLINE
self
.
on_operational
(
True
)
# resend QoS, in case of sth
self
.
set_qos
(
self
.
qos
[
0
],
self
.
qos
[
1
])
class
MessageReceiver
(
object
):
...
...
This diff is collapsed.
Click to expand it.
tests/run.py
+
3
−
1
View file @
ccf40787
...
...
@@ -22,7 +22,7 @@ if __name__ == '__main__':
snr
=
SingleNodeReconnector
(
NODE
,
ag
,
lt
)
snr
.
connect
()
ag
.
add
(
Consumer
(
Queue
(
'
siema-eniu
'
),
no_ack
=
True
))
ag
.
add
(
Consumer
(
Queue
(
'
siema-eniu
'
),
no_ack
=
False
,
qos
=
(
None
,
20
)
))
class
IPublishThread
(
threading
.
Thread
):
def
__init__
(
self
,
ag
):
...
...
@@ -43,4 +43,6 @@ if __name__ == '__main__':
while
True
:
time
.
sleep
(
30
)
lt
.
terminate
()
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