On 01/03/17 15:37, Gordon Sim wrote:
On 01/03/17 14:31, Kai Hudalla wrote:
Assuming that we have a link established between a Receiver (r) and a
Sender (s)
with a current link-credit of 4 and a delivery count of 20 on both sides.
When invoking r.flow(6), the given credit (6) is _added_ to the
receiver's
current credit resulting in r.getCredit() returning 10.
When the FLOW is then flushed to the sender, the sender seems to _add_
the link-
credit from the FLOW to its already existing credit. Analogously, this
results in
s.getCredit() now returning 10.
With this approach, it doesn't seem to be possible to stop the sender
from
sending messages. The only thing a receiver can do is to wait until
the sender
has used up all its credit (which may be a lot given that with the
current
approach the sender's credit can pile up substantially).
Or am I mistaken?
Can you specify a negative value to Receiver::flow()? I.e. would that
subtract from the credit and send a corresponding flow to the sender?
That seems to work for proton-c which has a similar API. (Not ideal, but
a workaround at least).
$ PN_TRACE_FRM=1 python revoke_credit.py
[0x563feb999040]: -> SASL
[0x563feb999040]: <- SASL
[0x563feb999040]:0 <- @sasl-mechanisms(64)
[sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS, :PLAIN]]
[0x563feb999040]:0 -> @sasl-init(65) [mechanism=:ANONYMOUS,
initial-response=b"[email protected]"]
[0x563feb999040]:0 <- @sasl-outcome(68) [code=0]
[0x563feb999040]: -> AMQP
[0x563feb999040]:0 -> @open(16) [container-id="023946f1-0197-4559-bd72-7fff5a687958",
hostname="localhost", channel-max=32767]
[0x563feb999040]:0 -> @begin(17) [next-outgoing-id=0,
incoming-window=2147483647, outgoing-window=2147483647]
[0x563feb999040]:0 -> @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
handle=0, role=true, snd-settle-mode=2, rcv-settle-mode=0, source=@source(40)
[address="examples", durable=0, timeout=0, dynamic=false], target=@target(41) [durable=0,
timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
[0x563feb999040]: <- AMQP
[0x563feb999040]:0 <- @open(16) [container-id="a6022696-2483-49f5-8ea6-a6f50db0e7ae", channel-max=32767,
offered-capabilities=@PN_SYMBOL[:"ANONYMOUS-RELAY"], properties={:product="qpid-cpp", :version="1.36.0",
:platform="Linux", :host="localhost.localdomain"}]
[0x563feb999040]:0 <- @begin(17) [remote-channel=0, next-outgoing-id=0,
incoming-window=2147483647, outgoing-window=2147483647]
[0x563feb999040]:0 <- @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
handle=0, role=false, snd-settle-mode=2, rcv-settle-mode=0, source=@source(40)
[address="examples", durable=0, timeout=0, dynamic=false, distribution-mode=:move],
target=@target(41) [durable=0, timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
[0x563feb999040]:0 -> @flow(19) [next-incoming-id=0,
incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
handle=0, delivery-count=0, link-credit=100, drain=false]
[0x563feb999040]:0 <- @transfer(20) [handle=0, delivery-id=0,
delivery-tag=b"\x00\x00\x00\x00", message-format=0, settled=false, more=false] (46)
"\x00Sp\xc0\x08\x05BP\x00@@R\x03\x00St\xc1\x14\x04\xa1\x02snR\x01\xa1\x02ts\x81\x14\xa7\xccS\x8fD\x99\x84\x00Sw\xa1\x03one"
one
[0x563feb999040]:0 -> @flow(19) [next-incoming-id=1,
incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
handle=0, delivery-count=1, link-credit=0, drain=false]
[0x563feb999040]:0 -> @disposition(21) [role=true, first=0, last=0,
settled=true, state=@accepted(36) []]
If there are messages in flight when you revoke the credit, they will
still be delivered from my tests.
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
from __future__ import print_function
import optparse
from proton.handlers import MessagingHandler
from proton.reactor import Container
class Recv(MessagingHandler):
def __init__(self, url, count):
super(Recv, self).__init__(prefetch=0)
self.url = url
self.count = 0
def on_start(self, event):
event.container.create_receiver(self.url)
def on_link_opened(self, event):
event.link.flow(100)
def on_message(self, event):
print(event.message.body)
self.count = self.count + 1
if self.count == 1:
event.receiver.flow(0 - event.receiver.credit)
parser = optparse.OptionParser(usage="usage: %prog [options]")
parser.add_option("-a", "--address", default="localhost:5672/examples",
help="address from which messages are received (default %default)")
parser.add_option("-m", "--messages", type="int", default=100,
help="number of messages to receive; 0 receives indefinitely (default %default)")
opts, args = parser.parse_args()
try:
Container(Recv(opts.address, opts.messages)).run()
except KeyboardInterrupt: pass
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]