MCPcopy Create free account
hub / github.com/apache/qpid-proton / TxRecv

Class TxRecv

python/examples/tx_recv.py:27–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27class TxRecv(MessagingHandler, TransactionHandler):
28 def __init__(self, url, messages, batch_size):
29 super(TxRecv, self).__init__(prefetch=0, auto_accept=False)
30 self.url = Url(url)
31 self.expected = messages
32 self.batch_size = batch_size
33 self.current_batch = 0
34 self.committed = 0
35
36 def on_start(self, event):
37 self.container = event.container
38 self.conn = self.container.connect(self.url)
39 self.receiver = self.container.create_receiver(self.conn, self.url.path)
40 self.container.declare_transaction(self.conn, handler=self)
41 self.transaction = None
42
43 def on_message(self, event):
44 print(event.message.body)
45 self.transaction.accept(event.delivery)
46 self.current_batch += 1
47 if self.current_batch == self.batch_size:
48 self.transaction.commit()
49 self.transaction = None
50
51 def on_transaction_declared(self, event):
52 self.receiver.flow(self.batch_size)
53 self.transaction = event.transaction
54
55 def on_transaction_committed(self, event):
56 self.committed += self.current_batch
57 self.current_batch = 0
58 if self.expected == 0 or self.committed < self.expected:
59 self.container.declare_transaction(self.conn, handler=self)
60 else:
61 event.connection.close()
62
63 def on_disconnected(self, event):
64 self.current_batch = 0
65
66
67parser = optparse.OptionParser(usage="usage: %prog [options]")

Callers 1

tx_recv.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected