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
63185483
Commit
63185483
authored
8 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fixed #19
parent
2e62c783
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/clustering/cluster.py
+20
-6
20 additions, 6 deletions
coolamqp/clustering/cluster.py
tests/test_clustering/test_a.py
+27
-0
27 additions, 0 deletions
tests/test_clustering/test_a.py
with
47 additions
and
6 deletions
coolamqp/clustering/cluster.py
+
20
−
6
View file @
63185483
...
...
@@ -96,7 +96,7 @@ class Cluster(object):
self
.
attache_group
.
add
(
con
)
return
con
,
fut
def
publish
(
self
,
message
,
exchange
=
None
,
routing_key
=
u
''
,
tx
=
Fals
e
):
def
publish
(
self
,
message
,
exchange
=
None
,
routing_key
=
u
''
,
tx
=
None
,
confirm
=
Non
e
):
"""
Publish a message.
...
...
@@ -104,11 +104,12 @@ class Cluster(object):
:param exchange: exchange to use. Default is the
"
direct
"
empty-name exchange.
:type exchange: unicode/bytes (exchange name) or Exchange object.
:param routing_key: routing key to use
:param tx: Whether to publish it transactionally.
If you choose so, you will receive a Future that can be used
to check it broker took responsibility for this message.
Note that if tx if False, and message cannot be delivered to broker at once,
it will be discarded.
:param confirm: Whether to publish it using confirms/transactions.
If you choose so, you will receive a Future that can be used
to check it broker took responsibility for this message.
Note that if tx if False, and message cannot be delivered to broker at once,
it will be discarded.
:param tx: deprecated, alias for confirm
:return: Future or None
"""
if
isinstance
(
exchange
,
Exchange
):
...
...
@@ -118,6 +119,19 @@ class Cluster(object):
else
:
exchange
=
exchange
.
encode
(
'
utf8
'
)
if
tx
is
not
None
:
# confirm is a drop-in replacement. tx is unfortunately named
warnings
.
warn
(
u
'
Use confirm kwarg instead
'
,
DeprecationWarning
)
if
confirm
is
None
:
tx
=
False
else
:
raise
RuntimeError
(
u
'
Using both tx= and confirm= at once does not make sense
'
)
elif
confirm
is
None
:
tx
=
False
else
:
tx
=
confirm
try
:
return
(
self
.
pub_tr
if
tx
else
self
.
pub_na
).
publish
(
message
,
exchange
,
routing_key
.
encode
(
'
utf8
'
))
except
Publisher
.
UnusablePublisher
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_clustering/test_a.py
+
27
−
0
View file @
63185483
...
...
@@ -74,6 +74,33 @@ class TestA(unittest.TestCase):
self
.
assertTrue
(
P
[
'
q
'
])
def
test_message_with_propos_confirm
(
self
):
P
=
{
'
q
'
:
False
}
def
ok
(
e
):
self
.
assertIsInstance
(
e
,
ReceivedMessage
)
self
.
assertEquals
(
e
.
body
,
b
'
hello
'
)
#bcoz u can compare memoryviews to their providers :D
self
.
assertEquals
(
e
.
properties
.
content_type
,
b
'
text/plain
'
)
self
.
assertEquals
(
e
.
properties
.
content_encoding
,
b
'
utf8
'
)
P
[
'
q
'
]
=
True
con
,
fut
=
self
.
c
.
consume
(
Queue
(
u
'
hello
'
,
exclusive
=
True
),
on_message
=
ok
,
no_ack
=
True
)
fut
.
result
()
self
.
c
.
publish
(
Message
(
b
'
hello
'
,
properties
=
{
'
content_type
'
:
b
'
text/plain
'
,
'
content_encoding
'
:
b
'
utf8
'
}),
routing_key
=
u
'
hello
'
,
confirm
=
True
).
result
()
self
.
assertRaises
(
RuntimeError
,
lambda
:
self
.
c
.
publish
(
Message
(
b
'
hello
'
,
properties
=
{
'
content_type
'
:
b
'
text/plain
'
,
'
content_encoding
'
:
b
'
utf8
'
}),
routing_key
=
u
'
hello
'
,
confirm
=
True
,
tx
=
True
).
result
())
time
.
sleep
(
1
)
self
.
assertTrue
(
P
[
'
q
'
])
def
test_message_with_propos
(
self
):
...
...
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