You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2015/03/06 21:58:05 UTC
[2/2] qpid-proton git commit: NO-JIRA: added sender and receiver
example that accept incoming connections, demonstrating non-intermediated use.
NO-JIRA: added sender and receiver example that accept incoming connections, demonstrating non-intermediated use.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/5df0bbc2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/5df0bbc2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/5df0bbc2
Branch: refs/heads/master
Commit: 5df0bbc2df27b4a4582672b12975ec3aeee8ee06
Parents: aebacd0
Author: Gordon Sim <gs...@redhat.com>
Authored: Fri Mar 6 19:25:52 2015 +0000
Committer: Gordon Sim <gs...@redhat.com>
Committed: Fri Mar 6 19:25:52 2015 +0000
----------------------------------------------------------------------
examples/python/direct_recv.py | 56 +++++++++++++++++++++++++++++++++++
examples/python/direct_send.py | 50 +++++++++++++++++++++++++++++++
examples/python/test_examples.py | 21 +++++++++++++
3 files changed, 127 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/direct_recv.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_recv.py b/examples/python/direct_recv.py
new file mode 100755
index 0000000..dd0e3c9
--- /dev/null
+++ b/examples/python/direct_recv.py
@@ -0,0 +1,56 @@
+#!/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.
+#
+
+import optparse
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Recv(MessagingHandler):
+ def __init__(self, url, count):
+ super(Recv, self).__init__()
+ self.url = url
+ self.expected = count
+ self.received = 0
+
+ def on_start(self, event):
+ self.acceptor = event.container.listen(self.url)
+
+ def on_message(self, event):
+ if self.expected == 0 or self.received < self.expected:
+ print event.message.body
+ self.received += 1
+ if self.received == self.expected:
+ event.receiver.close()
+ event.connection.close()
+ self.acceptor.close()
+
+parser = optparse.OptionParser(usage="usage: %prog [options]")
+parser.add_option("-a", "--address", default="localhost:8888",
+ 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
+
+
+
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/direct_send.py
----------------------------------------------------------------------
diff --git a/examples/python/direct_send.py b/examples/python/direct_send.py
new file mode 100755
index 0000000..bfeb357
--- /dev/null
+++ b/examples/python/direct_send.py
@@ -0,0 +1,50 @@
+#!/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.
+#
+
+import optparse
+from proton import Message
+from proton.handlers import MessagingHandler
+from proton.reactor import Container
+
+class Send(MessagingHandler):
+ def __init__(self, url):
+ super(Send, self).__init__()
+ self.url = url
+ self.sent = 0
+ self.confirmed = 0
+
+ def on_start(self, event):
+ event.container.listen(self.url)
+
+ def on_sendable(self, event):
+ while event.sender.credit:
+ msg = Message(id=(self.sent+1), body={'sequence':(self.sent+1)})
+ event.sender.send(msg)
+ self.sent += 1
+
+ def on_accepted(self, event):
+ self.confirmed += 1
+
+ def on_disconnected(self, event):
+ self.sent = self.confirmed
+
+try:
+ Container(Send("localhost:8888")).run()
+except KeyboardInterrupt: pass
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/5df0bbc2/examples/python/test_examples.py
----------------------------------------------------------------------
diff --git a/examples/python/test_examples.py b/examples/python/test_examples.py
index 49abb8a..c3eaa11 100644
--- a/examples/python/test_examples.py
+++ b/examples/python/test_examples.py
@@ -107,3 +107,24 @@ class ExamplesTest(unittest.TestCase):
def test_tx_send_tx_recv(self):
self.test_simple_send_recv(recv='tx_recv.py', send='tx_send.py')
+
+ def test_simple_send_direct_recv(self):
+ self.maxDiff = None
+ r = subprocess.Popen(['direct_recv.py'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ time.sleep(0.5)
+ s = subprocess.Popen(['simple_send.py', '-a', 'localhost:8888'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ s.wait()
+ r.wait()
+ actual = [l.strip() for l in r.stdout]
+ expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+ self.assertEqual(actual, expected)
+
+ def test_direct_send_simple_recv(self):
+ s = subprocess.Popen(['direct_send.py'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ time.sleep(0.5)
+ r = subprocess.Popen(['simple_recv.py', '-a', 'localhost:8888'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ r.wait()
+ actual = [l.strip() for l in r.stdout]
+ expected = ["{'sequence': %iL}" % (i+1) for i in range(100)]
+ s.terminate()
+ self.assertEqual(actual, expected)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org