http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/async.pm ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/async.pm b/examples/perl/messenger/async.pm deleted file mode 100644 index 5cd350b..0000000 --- a/examples/perl/messenger/async.pm +++ /dev/null @@ -1,120 +0,0 @@ -# -# 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. -# - -use qpid_proton; - -package async::CallbackAdapter; - -sub new { - my ($class) = @_; - my ($self) = {}; - - my $messenger = $_[1]; - - $self->{_messenger} = $messenger; - $messenger->set_blocking(0); - $messenger->set_incoming_window(1024); - $messenger->set_outgoing_window(1024); - - my $message = qpid::proton::Message->new(); - $self->{_message} = $message; - $self->{_incoming} = $message; - $self->{_tracked} = {}; - - bless $self, $class; - return $self; -} - -sub run { - my ($self) = @_; - - $self->{_running} = 1; - - my $messenger = $self->{_messenger}; - - $messenger->start(); - $self->on_start(); - - do { - $messenger->work; - $self->process_outgoing; - $self->process_incoming; - } while($self->{_running}); - - $messenger->stop(); - - while(!$messenger->stopped()) { - $messenger->work; - $self->process_outgoing; - $self->process_incoming; - } - - $self->on_stop(); -} - -sub stop { - my ($self) = @_; - - $self->{_running} = 0; -} - -sub process_outgoing { - my ($self) = @_; - my $tracked = $self->{_tracked}; - - foreach $key (keys %{$tracked}) { - my $on_status = $tracked->{$key}; - if (defined($on_status)) { - if (!($on_status eq qpid::proton::Tracker::PENDING)) { - $self->$on_status($status); - $self->{_messenger}->settle($t); - # delete the settled item - undef $tracked->{$key}; - } - } - } -} - -sub process_incoming { - my ($self) = @_; - my $messenger = $self->{_messenger}; - - while ($messenger->incoming > 0) { - my $message = $self->{_message}; - my $t = $messenger->get($message); - - $self->on_receive($message); - $messenger->accept($t); - } -} - -sub send { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $tracked = $self->{_tracked}; - my $message = $_[1]; - my $on_status = $_[2] || undef; - - my $tracker = $messenger->put($message); - - $tracked->{$tracker} = $on_status if (defined($on_status)); -} - - -1;
http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/client.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/client.pl b/examples/perl/messenger/client.pl deleted file mode 100755 index a6d8378..0000000 --- a/examples/perl/messenger/client.pl +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Long; -use Pod::Usage; - -use qpid_proton; - -my $reply_to = "~/replies"; -my $help = 0; -my $man = 0; - -GetOptions( - "reply_to=s", \$reply_to, - man => \$man, - "help|?" => \$help - ) or pod2usage(2); -pod2usage(1) if $help; -pod2usage(-exitval => 0, -verbose => 2) if $man; - -# get the address to use and show help if it's missing -my $address = $ARGV[0]; -pod2usage(1) if !$address; - -my $messenger = new qpid::proton::Messenger(); -$messenger->start; - -my $message = new qpid::proton::Message(); -$message->set_address($address); -$message->set_reply_to($reply_to); -$message->set_subject("Subject"); -$message->set_content("Yo!"); - -print "Sending to: $address\n"; - -$messenger->put($message); -$messenger->send; - -if($reply_to =~ /^~\//) { - print "Waiting on returned message.\n"; - $messenger->receive(1); - - $messenger->get($message); - print $message->get_address . " " . $message->get_subject . "\n"; -} - -$messenger->stop; - -__END__ - -=head1 NAME - -client - Proton example application for Perl. - -=head1 SYNOPSIS - -client.pl [OPTIONS] <address> <subject> - - Options: - --reply_to - The reply to address to be used. (default: ~/replies) - --help - This help message. - --man - Show the full docementation. - -=over 8 - -=item B<--reply_to> - -Specifies the reply address to be used for responses from the server. - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the man page and exits. - -=back - -=head2 ADDRESS - -The form an address takes is: - -[amqp://]<domain>[/name] - -=cut http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/recv.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/recv.pl b/examples/perl/messenger/recv.pl deleted file mode 100755 index 801f6a2..0000000 --- a/examples/perl/messenger/recv.pl +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use warnings; - -use Scalar::Util qw(reftype); -use Data::Dumper; - -use qpid_proton; - -sub usage { - exit(0); -} - -my @addresses = @ARGV; -@addresses = ("~0.0.0.0") unless $addresses[0]; - -my $messenger = new qpid::proton::Messenger(); -my $msg = new qpid::proton::Message(); - -$messenger->start(); - -foreach (@addresses) -{ - print "Subscribing to $_\n"; - $messenger->subscribe($_); -} - -for(;;) -{ - $messenger->receive(10); - - while ($messenger->incoming() > 0) - { - $messenger->get($msg); - - print "\n"; - print "Address: " . $msg->get_address() . "\n"; - print "Subject: " . $msg->get_subject() . "\n" unless !defined($msg->get_subject()); - print "Body: "; - - my $body = $msg->get_body(); - my $body_type = $msg->get_body_type(); - - if (!defined($body_type)) { - print "The body type wasn't defined!\n"; - } elsif ($body_type == qpid::proton::BOOL) { - print "[BOOL]\n"; - print "" . ($body ? "TRUE" : "FALSE") . "\n"; - } elsif ($body_type == qpid::proton::MAP) { - print "[HASH]\n"; - print Dumper(\%{$body}) . "\n"; - } elsif ($body_type == qpid::proton::ARRAY) { - print "[ARRAY]\n"; - print Data::Dumper->Dump($body) . "\n"; - } elsif ($body_type == qpid::proton::LIST) { - print "[LIST]\n"; - print Data::Dumper->Dump($body) . "\n"; - } else { - print "[$body_type]\n"; - print "$body\n"; - } - - print "Properties:\n"; - my $props = $msg->get_properties(); - foreach (keys $props) { - print "\t$_=$props->{$_}\n"; - } - print "Instructions:\n"; - my $instructions = $msg->get_instructions; - foreach (keys $instructions) { - print "\t$_=" . $instructions->{$_} . "\n"; - } - print "Annotations:\n"; - my $annotations = $msg->get_annotations(); - foreach (keys $annotations) { - print "\t$_=" . $annotations->{$_} . "\n"; - } - } -} - -die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/recv_async.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/recv_async.pl b/examples/perl/messenger/recv_async.pl deleted file mode 100755 index 9a2195a..0000000 --- a/examples/perl/messenger/recv_async.pl +++ /dev/null @@ -1,84 +0,0 @@ -# -# 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. -# - -use qpid_proton; -use async; - -package async::Receiver; - -@ISA = (async::CallbackAdapter); - -sub on_start { - my ($self) = @_; - my $args = $_[1] || ("amqp://~0.0.0.0"); - my $messenger = $self->{_messenger}; - - foreach $arg ($args) { - $messenger->subscribe($arg); - } - - $messenger->receive(); -} - -sub on_receive { - my ($self) = @_; - my $msg = $_[1]; - my $message = $self->{_message}; - my $text = ""; - - if (defined($msg->get_body)) { - $text = $msg->get_body; - if ($text eq "die") { - $self->stop; - } - } else { - $text = $message->get_subject; - } - - $text = "" if (!defined($text)); - - print "Received: $text\n"; - - if ($msg->get_reply_to) { - print "Sending reply to: " . $msg->get_reply_to . "\n"; - $message->clear; - $message->set_address($msg->get_reply_to()); - $message->set_body("Reply for ", $msg->get_body); - $self->send($message); - } -} - -sub on_status { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $status = $_[1]; - - print "Status: ", $status, "\n"; -} - -sub on_stop { - print "Stopped.\n" -} - -package main; - -our $messenger = new qpid::proton::Messenger(); -our $app = new async::Receiver($messenger); - -$app->run(); http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/send.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/send.pl b/examples/perl/messenger/send.pl deleted file mode 100755 index 27893ce..0000000 --- a/examples/perl/messenger/send.pl +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Std; - -use qpid_proton; - -$Getopt::Std::STANDARD_HELP_VERSION = 1; - -sub VERSION_MESSAGE() { -} - -sub HELP_MESSAGE() { - print "Usage: send.pl [OPTIONS] -a <ADDRESS>\n"; - print "Options:\n"; - print "\t-s - the message subject\n"; - print "\t-C - the message content\n"; - print "\t<ADDRESS> - amqp://<domain>[/<name>]\n"; - print "\t-h - this message\n"; - - exit; -} - -my %options = (); -getopts("a:C:s:h:", \%options) or HELP_MESSAGE(); - -my $address = $options{a} || "amqp://0.0.0.0"; -my $subject = $options{s} || localtime(time); -my $content = $options{C} || ""; - -my $msg = new qpid::proton::Message(); -my $messenger = new qpid::proton::Messenger(); - -$messenger->start(); - -my @messages = @ARGV; -@messages = ("This is a test. " . localtime(time)) unless $messages[0]; - -foreach (@messages) -{ - $msg->set_address($address); - $msg->set_subject($subject); - $msg->set_body($content); - # try a few different body types - my $body_type = int(rand(6)); - $msg->set_property("sent", "" . localtime(time)); - $msg->get_instructions->{"fold"} = "yes"; - $msg->get_instructions->{"spindle"} = "no"; - $msg->get_instructions->{"mutilate"} = "no"; - $msg->get_annotations->{"version"} = 1.0; - $msg->get_annotations->{"pill"} = "RED"; - - SWITCH: { - $body_type == 0 && do { $msg->set_body("It is now " . localtime(time));}; - $body_type == 1 && do { $msg->set_body(rand(65536)); }; - $body_type == 2 && do { $msg->set_body(int(rand(2)), qpid::proton::BOOL); }; - $body_type == 3 && do { $msg->set_body({"foo" => "bar"}); }; - $body_type == 4 && do { $msg->set_body([4, [1, 2, 3.1, 3.4E-5], 8, 15, 16, 23, 42]); }; - $body_type == 5 && do { $msg->set_body(int(rand(65535))); } - } - - $messenger->put($msg); - print "Sent: " . $msg->get_body . " [CONTENT TYPE: " . $msg->get_body_type . "]\n"; -} - -$messenger->send(); -$messenger->stop(); - -die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/send_async.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/send_async.pl b/examples/perl/messenger/send_async.pl deleted file mode 100644 index 2f9408a..0000000 --- a/examples/perl/messenger/send_async.pl +++ /dev/null @@ -1,97 +0,0 @@ -# -# 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. -# - -use Getopt::Std; -use qpid_proton; -use async; - -$Getopt::Std::STANDARD_HELP_VERSION = 1; - -sub VERSION_MESSAGE() {} - -sub HELP_MESSAGE() { - print "Usage: send_async.pl [OPTIONS] <msg_0> <msg_1> ...\n"; - print "Options:\n"; - print "\t-a - the message address (def. amqp://0.0.0.0)\n"; - print "\t-r - the reply-to address: //<domain>[/<name>]\n"; - print "\t msg_# - a text string to send\n"; -} - -my %optons = (); -getopts("a:r:", \%options) or usage(); - -our $address = $options{a} || "amqp://0.0.0.0"; -our $replyto = $options{r} || "~/#"; - -package async::Sender; - -@ISA = (async::CallbackAdapter); - -sub on_start { - my ($self) = @_; - my $message = $self->{_message}; - my $messenger = $self->{_messenger}; - my $args = $_[1] || ("Hello world!"); - - print "Started\n"; - - $message->clear; - $message->set_address("amqp://0.0.0.0"); - $message->set_reply_to($replyto) if (defined($replyto)); - - foreach $arg ($args) { - $message->set_body($arg); - if ($replyto) { - $message->set_reply_to($replyto); - } - $self->send($message, "on_status"); - } - - $messenger->receive() if (defined($replyto)); -} - -sub on_status { - my ($self) = @_; - my $messenger = $self->{_messenger}; - my $status = $_[1] || ""; - - print "Status: ", $status, "\n"; -} - -sub on_receive { - my ($self) = @_; - my $message = $_[1]; - my $text = $message->get_body || "[empty]"; - - print "Received: " . $text . "\n"; - - $self->stop(); -} - -sub on_stop { - print "Stopped\n"; -} - - -package main; - -our $msgr = new qpid::proton::Messenger(); -our $app = async::Sender->new($msgr); - -$app->run; http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/perl/messenger/server.pl ---------------------------------------------------------------------- diff --git a/examples/perl/messenger/server.pl b/examples/perl/messenger/server.pl deleted file mode 100755 index c13d4d5..0000000 --- a/examples/perl/messenger/server.pl +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env perl -# -# 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. -# - -use strict; -use warnings; -use Getopt::Long; -use Pod::Usage; - -use qpid_proton; - -my $help = 0; -my $man = 0; - -GetOptions( - man => \$man, - "help|?" => \$help - ) or pod2usage(2); - -pod2usage(1) if $help; -pod2usage(-exitval => 0, -verbose => 2) if $man; - -pod2usage(2) unless scalar(@ARGV); - -# create a messenger for receiving and holding -# incoming messages -our $messenger = new qpid::proton::Messenger; -$messenger->start; - -# subscribe the messenger to all addresses specified sources -foreach (@ARGV) { - $messenger->subscribe($_); -} - -sub dispatch { - my $request = $_[0]; - my $reply = $_[1]; - - if ($request->get_subject) { - $reply->set_subject("Re: " . $request->get_subject); - } - - $reply->set_properties($request->get_properties); - print "Dispatched " . $request->get_subject . "\n"; - my $properties = $request->get_properties; - foreach (keys %{$properties}) { - my $value = $properties->{%_}; - print "\t$_: $value\n"; - } -} - -our $message = new qpid::proton::Message; -our $reply = new qpid::proton::Message; - -while(1) { - $messenger->receive(1) if $messenger->incoming < 10; - - if ($messenger->incoming > 0) { - $messenger->get($message); - - if ($message->get_reply_to) { - print $message->get_reply_to . "\n"; - $reply->set_address($message->get_reply_to); - $reply->set_correlation_id($message->get_correlation_id); - $reply->set_body($message->get_body); - } - dispatch($message, $reply); - $messenger->put($reply); - $messenger->send; - } -} - -$message->stop; - -__END__ - -=head1 NAME - -server - Proton example server application for Perl. - -=head1 SYNOPSIS - -server.pl [OPTIONS] <addr1> ... <addrn> - - Options: - --help - This help message. - --man - Show the full documentation. - -=over 8 - -=item B<--help> - -Prints a brief help message and exits. - -=item B<--man> - -Prints the man page and exits. - -=back - -=head2 ADDRESS - -The form an address takes is: - -[amqp://]<domain>[/name] - -=cut http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/php/messenger/recv.php ---------------------------------------------------------------------- diff --git a/examples/php/messenger/recv.php b/examples/php/messenger/recv.php deleted file mode 100644 index 05ece80..0000000 --- a/examples/php/messenger/recv.php +++ /dev/null @@ -1,49 +0,0 @@ -<?php - -/** - * 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. - **/ - -include("proton.php"); - -$mess = new Messenger(); -$mess->start(); - -if ($argv[1]) { - $mess->subscribe($argv[1]); -} else { - $mess->subscribe("amqp://~0.0.0.0"); -} - -$msg = new Message(); -while (true) { - $mess->recv(10); - while ($mess->incoming) { - try { - $mess->get($msg); - } catch (Exception $e) { - print "$e\n"; - continue; - } - - print "$msg->address, $msg->subject, $msg->body\n"; - } -} - -$mess->stop(); -?> http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/php/messenger/send.php ---------------------------------------------------------------------- diff --git a/examples/php/messenger/send.php b/examples/php/messenger/send.php deleted file mode 100644 index 599f7eb..0000000 --- a/examples/php/messenger/send.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** - * 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. - **/ - -include("proton.php"); - -$mess = new Messenger(); -$mess->start(); - -$msg = new Message(); -if ($argv[1]) { - $msg->address = $argv[1]; -} else { - $msg->address = "amqp://0.0.0.0"; -} -$msg->subject = "Hello World!"; -$msg->body = "this is a test"; - -$mess->put($msg); -$mess->send(); -print "sent: $msg->subject\n"; - -$mess->stop(); -?> http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/README ---------------------------------------------------------------------- diff --git a/examples/python/README b/examples/python/README deleted file mode 100644 index 9051187..0000000 --- a/examples/python/README +++ /dev/null @@ -1,187 +0,0 @@ -Most (though not all) of the current examples require a broker or -similar intermediary that supports the AMQP 1.0 protocol, allows -anonymous connections and accepts links to and from a node named -'examples'. A very simple broker emulating script - broker.py - is -provided against which the examples can also be run (transactions are -not yet supported in this script). - -Note: For builds that include SASL support via the cyrus sasl library, -those examples that accept incoming connections may require some SASL -configuration which is described below. - ------------------------------------------------------------------- - -helloworld.py - -Basic example that connects to an intermediary on localhost:5672, -establishes a subscription from the 'examples' node on that -intermediary, then creates a sending link to the same node and sends -one message. On receving the message back via the subcription, the -connection is closed. - -helloworld_blocking.py - -The same as the basic helloworld.py, but using a -synchronous/sequential style wrapper on top of the -asynchronous/reactive API. The purpose of this example is just to show -how different functionality can be easily layered should it be -desired. - -helloworld_direct.py - -A variant of the basic helloworld example, that does not use an -intermediary, but listens for incoming connections itself. It -establishes a connection to itself with a link over which a single -message is sent. This demonstrates the ease with which a simple daemon -can be built using the API. - -helloworld_tornado.py -helloworld_direct_tornado.py - -These are variant of the helloworld.py and helloworld_direct.py -examples that use the event loop from the tornado library, rather than -that provided within proton itself and demonstrate how proton can be -used with external loops. - -------------------------------------------------------------------- - -simple_send.py - -An example of sending a fixed number of messages and tracking their -(asynchronous) acknowledgement. Handles disconnection while -maintaining an at-least-once guarantee (there may be duplicates, but -no message in the sequence should be lost). Messages are sent through -the 'examples' node on an intermediary accessible on port 5672 on -localhost. - -simple_recv.py - -Subscribes to the 'examples' node on an intermediary accessible on port 5672 on -localhost. Simply prints out the body of received messages. - -db_send.py - -A more realistic sending example, where the messages come from records -in a simple database table. On being acknowledged the records can be -deleted from the table. The database access is done in a separate -thread, so as not to block the event thread during data -access. Messages are sent through the 'examples' node on an -intermediary accessible on port 5672 on localhost. - -db_recv.py - -A receiving example that records messages received from the 'examples' -node on localhost:5672 in a database table and only acknowledges them -when the insert completes. Database access is again done in a separate -thread from the event loop. - -db_ctrl.py - -A utility for setting up the database tables for the two examples -above. Takes two arguments, the action to perform and the name of the -database on which to perfom it. The database used by db_send.py is -src_db, that by db_recv.py is dst_db. The valid actions are 'init', -which creates the table, 'list' which displays the contents and -'insert' which inserts records from standard-in and is used to -populate src_db, e.g. for i in `seq 1 50`; do echo "Message-$i"; done -| ./db_ctrl.py insert src_db. - -tx_send.py - -A sender that sends messages in atomic batches using local -transactions (this example does not persist the messages in any way). - -tx_recv.py - -A receiver example that accepts batches of messages using local -transactions. - -tx_recv_interactive.py - -A testing utility that allow interactive control of the -transactions. Actions are keyed in to the console, 'fetch' will -request another message, 'abort' will abort the transaction, 'commit' -will commit it. - -The various send/recv examples can be mixed and matched if desired. - -direct_send.py - -An example that accepts incoming links and connections over which it -will then send out messages. Can be used with simple_recv.py or -db_recv.py for direct, non-intermediated communication. - -direct_recv.py - -An example that accepts incoming links and connections over which it -will then receive messages, printing out the content. Can be used with -simple_send.py or db_send.py for direct, non-intermediated -communication. - -------------------------------------------------------------------- - -client.py - -The client part of a request-response example. Sends requests and -prints out responses. Requires an intermediary that supports the AMQP -1.0 dynamic nodes on which the responses are received. The requests -are sent through the 'examples' node. - -server.py - -The server part of a request-response example, that receives requests -via the examples node, converts the body to uppercase and sends the -result back to the indicated reply address. - -sync_client.py - -A variant of the client part, that uses a blocking/synchronous style -instead of the reactive/asynchronous style. - -client_http.py - -A variant of the client part that takes the input to be submitted in -the request over HTTP (point your browser to localhost:8888/client) - -server_tx.py - -A variant of the server part that consumes the request and sends out -the response atomically in a local transaction. - -direct_server.py - -A variant of the server part of a request-response example, that -accepts incoming connections and does not need an intermediary. Much -like the original server, it receives incoming requests, converts the -body to uppercase and sends the result back to the indicated reply -address. Can be used in conjunction with any of the client -alternatives. - -------------------------------------------------------------------- - -selected_recv.py - -An example that uses a selector filter. - -------------------------------------------------------------------- - -recurring_timer.py - -An example showing a simple timer event. - -recurring_timer_tornado.py - -A variant of the above that uses the tornado eventloop instead. - -------------------------------------------------------------------- - -SASL configuration - -If your build includes extra SASL support (provided via the cyrus SASL -library), you may need to provide some configuration to enable -examples that accept incoming connections (i.e. those with 'direct' in -the name). This is done by supplying a config file name -proton-server.conf. The directory in which it is in can be specified -via the PN_SASL_CONFIG_PATH environment variable. A simple example -config file is included along with these examples, enabling only the -EXTERNAL and ANONYMOUS mechanisms by default. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/abstract_server.py ---------------------------------------------------------------------- diff --git a/examples/python/abstract_server.py b/examples/python/abstract_server.py deleted file mode 100755 index fed7fb2..0000000 --- a/examples/python/abstract_server.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 -from proton_server import Server - -class Application(Server): - def __init__(self, host, address): - super(Application, self).__init__(host, address) - - def on_request(self, request, reply_to): - response = request.upper() - self.send(response, reply_to) - print("Request from: %s" % reply_to) - -try: - Application("localhost:5672", "examples").run() -except KeyboardInterrupt: pass - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/broker.py ---------------------------------------------------------------------- diff --git a/examples/python/broker.py b/examples/python/broker.py deleted file mode 100755 index 8769268..0000000 --- a/examples/python/broker.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/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 collections, optparse -from proton import Endpoint, generate_uuid -from proton.handlers import MessagingHandler -from proton.reactor import Container - -class Queue(object): - def __init__(self, dynamic=False): - self.dynamic = dynamic - self.queue = collections.deque() - self.consumers = [] - - def subscribe(self, consumer): - self.consumers.append(consumer) - - def unsubscribe(self, consumer): - if consumer in self.consumers: - self.consumers.remove(consumer) - return len(self.consumers) == 0 and (self.dynamic or self.queue.count == 0) - - def publish(self, message): - self.queue.append(message) - self.dispatch() - - def dispatch(self, consumer=None): - if consumer: - c = [consumer] - else: - c = self.consumers - while self._deliver_to(c): pass - - def _deliver_to(self, consumers): - try: - result = False - for c in consumers: - if c.credit: - c.send(self.queue.popleft()) - result = True - return result - except IndexError: # no more messages - return False - -class Broker(MessagingHandler): - def __init__(self, url): - super(Broker, self).__init__() - self.url = url - self.queues = {} - - def on_start(self, event): - self.acceptor = event.container.listen(self.url) - - def _queue(self, address): - if address not in self.queues: - self.queues[address] = Queue() - return self.queues[address] - - def on_link_opening(self, event): - if event.link.is_sender: - if event.link.remote_source.dynamic: - address = str(generate_uuid()) - event.link.source.address = address - q = Queue(True) - self.queues[address] = q - q.subscribe(event.link) - elif event.link.remote_source.address: - event.link.source.address = event.link.remote_source.address - self._queue(event.link.source.address).subscribe(event.link) - elif event.link.remote_target.address: - event.link.target.address = event.link.remote_target.address - - def _unsubscribe(self, link): - if link.source.address in self.queues and self.queues[link.source.address].unsubscribe(link): - del self.queues[link.source.address] - - def on_link_closing(self, event): - if event.link.is_sender: - self._unsubscribe(event.link) - - def on_connection_closing(self, event): - self.remove_stale_consumers(event.connection) - - def on_disconnected(self, event): - self.remove_stale_consumers(event.connection) - - def remove_stale_consumers(self, connection): - l = connection.link_head(Endpoint.REMOTE_ACTIVE) - while l: - if l.is_sender: - self._unsubscribe(l) - l = l.next(Endpoint.REMOTE_ACTIVE) - - def on_sendable(self, event): - self._queue(event.link.source.address).dispatch(event.link) - - def on_message(self, event): - self._queue(event.link.target.address).publish(event.message) - -parser = optparse.OptionParser(usage="usage: %prog [options]") -parser.add_option("-a", "--address", default="localhost:5672", - help="address router listens on (default %default)") -opts, args = parser.parse_args() - -try: - Container(Broker(opts.address)).run() -except KeyboardInterrupt: pass http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/client.py ---------------------------------------------------------------------- diff --git a/examples/python/client.py b/examples/python/client.py deleted file mode 100755 index 86f2c76..0000000 --- a/examples/python/client.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/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, unicode_literals -import optparse -from proton import Message -from proton.handlers import MessagingHandler -from proton.reactor import Container, DynamicNodeProperties - -class Client(MessagingHandler): - def __init__(self, url, requests): - super(Client, self).__init__() - self.url = url - self.requests = requests - - def on_start(self, event): - self.sender = event.container.create_sender(self.url) - self.receiver = event.container.create_receiver(self.sender.connection, None, dynamic=True) - - def next_request(self): - if self.receiver.remote_source.address: - req = Message(reply_to=self.receiver.remote_source.address, body=self.requests[0]) - self.sender.send(req) - - def on_link_opened(self, event): - if event.receiver == self.receiver: - self.next_request() - - def on_message(self, event): - print("%s => %s" % (self.requests.pop(0), event.message.body)) - if self.requests: - self.next_request() - else: - event.connection.close() - -REQUESTS= ["Twas brillig, and the slithy toves", - "Did gire and gymble in the wabe.", - "All mimsy were the borogroves,", - "And the mome raths outgrabe."] - -parser = optparse.OptionParser(usage="usage: %prog [options]", - description="Send requests to the supplied address and print responses.") -parser.add_option("-a", "--address", default="localhost:5672/examples", - help="address to which messages are sent (default %default)") -opts, args = parser.parse_args() - -Container(Client(opts.address, args or REQUESTS)).run() - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/client_http.py ---------------------------------------------------------------------- diff --git a/examples/python/client_http.py b/examples/python/client_http.py deleted file mode 100755 index bf65639..0000000 --- a/examples/python/client_http.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/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 tornado.ioloop -import tornado.web -from proton import Message -from proton.handlers import MessagingHandler -from proton_tornado import Container - -class Client(MessagingHandler): - def __init__(self, host, address): - super(Client, self).__init__() - self.host = host - self.address = address - self.sent = [] - self.pending = [] - self.reply_address = None - self.sender = None - self.receiver = None - - def on_start(self, event): - conn = event.container.connect(self.host) - self.sender = event.container.create_sender(conn, self.address) - self.receiver = event.container.create_receiver(conn, None, dynamic=True) - - def on_link_opened(self, event): - if event.receiver == self.receiver: - self.reply_address = event.link.remote_source.address - self.do_request() - - def on_sendable(self, event): - self.do_request() - - def on_message(self, event): - if self.sent: - request, handler = self.sent.pop(0) - print("%s => %s" % (request, event.message.body)) - handler(event.message.body) - self.do_request() - - def do_request(self): - if self.pending and self.reply_address and self.sender.credit: - request, handler = self.pending.pop(0) - self.sent.append((request, handler)) - req = Message(reply_to=self.reply_address, body=request) - self.sender.send(req) - - def request(self, body, handler): - self.pending.append((body, handler)) - self.do_request() - self.container.touch() - -class ExampleHandler(tornado.web.RequestHandler): - def initialize(self, client): - self.client = client - - def get(self): - self._write_open() - self._write_form() - self._write_close() - - @tornado.web.asynchronous - def post(self): - client.request(self.get_body_argument("message"), lambda x: self.on_response(x)) - - def on_response(self, body): - self.set_header("Content-Type", "text/html") - self._write_open() - self._write_form() - self.write("Response: " + body) - self._write_close() - self.finish() - - def _write_open(self): - self.write('<html><body>') - - def _write_close(self): - self.write('</body></html>') - - def _write_form(self): - self.write('<form action="/client" method="POST">' - 'Request: <input type="text" name="message">' - '<input type="submit" value="Submit">' - '</form>') - - -loop = tornado.ioloop.IOLoop.instance() -client = Client("localhost:5672", "examples") -client.container = Container(client, loop=loop) -client.container.initialise() -app = tornado.web.Application([tornado.web.url(r"/client", ExampleHandler, dict(client=client))]) -app.listen(8888) -try: - loop.start() -except KeyboardInterrupt: - loop.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/db_common.py ---------------------------------------------------------------------- diff --git a/examples/python/db_common.py b/examples/python/db_common.py deleted file mode 100755 index 54af87b..0000000 --- a/examples/python/db_common.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/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. -# - -try: - import Queue -except: - import queue as Queue - -import sqlite3 -import threading - -class Db(object): - def __init__(self, db, injector): - self.db = db - self.injector = injector - self.tasks = Queue.Queue() - self.position = None - self.pending_events = [] - self.running = True - self.thread = threading.Thread(target=self._process) - self.thread.daemon=True - self.thread.start() - - def close(self): - self.tasks.put(lambda conn: self._close()) - - def reset(self): - self.tasks.put(lambda conn: self._reset()) - - def load(self, records, event=None): - self.tasks.put(lambda conn: self._load(conn, records, event)) - - def get_id(self, event): - self.tasks.put(lambda conn: self._get_id(conn, event)) - - def insert(self, id, data, event=None): - self.tasks.put(lambda conn: self._insert(conn, id, data, event)) - - def delete(self, id, event=None): - self.tasks.put(lambda conn: self._delete(conn, id, event)) - - def _reset(self, ignored=None): - self.position = None - - def _close(self, ignored=None): - self.running = False - - def _get_id(self, conn, event): - cursor = conn.execute("SELECT * FROM records ORDER BY id DESC") - row = cursor.fetchone() - if event: - if row: - event.id = row['id'] - else: - event.id = 0 - self.injector.trigger(event) - - def _load(self, conn, records, event): - if self.position: - cursor = conn.execute("SELECT * FROM records WHERE id > ? ORDER BY id", (self.position,)) - else: - cursor = conn.execute("SELECT * FROM records ORDER BY id") - while not records.full(): - row = cursor.fetchone() - if row: - self.position = row['id'] - records.put(dict(row)) - else: - break - if event: - self.injector.trigger(event) - - def _insert(self, conn, id, data, event): - if id: - conn.execute("INSERT INTO records(id, description) VALUES (?, ?)", (id, data)) - else: - conn.execute("INSERT INTO records(description) VALUES (?)", (data,)) - if event: - self.pending_events.append(event) - - def _delete(self, conn, id, event): - conn.execute("DELETE FROM records WHERE id=?", (id,)) - if event: - self.pending_events.append(event) - - def _process(self): - conn = sqlite3.connect(self.db) - conn.row_factory = sqlite3.Row - with conn: - while self.running: - f = self.tasks.get(True) - try: - while True: - f(conn) - f = self.tasks.get(False) - except Queue.Empty: pass - conn.commit() - for event in self.pending_events: - self.injector.trigger(event) - self.pending_events = [] - self.injector.close() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/db_ctrl.py ---------------------------------------------------------------------- diff --git a/examples/python/db_ctrl.py b/examples/python/db_ctrl.py deleted file mode 100755 index 04770ce..0000000 --- a/examples/python/db_ctrl.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/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 sqlite3 -import sys - -if len(sys.argv) < 3: - print("Usage: %s [init|insert|list] db" % sys.argv[0]) -else: - conn = sqlite3.connect(sys.argv[2]) - with conn: - if sys.argv[1] == "init": - conn.execute("DROP TABLE IF EXISTS records") - conn.execute("CREATE TABLE records(id INTEGER PRIMARY KEY AUTOINCREMENT, description TEXT)") - conn.commit() - elif sys.argv[1] == "list": - cursor = conn.cursor() - cursor.execute("SELECT * FROM records") - rows = cursor.fetchall() - for r in rows: - print(r) - elif sys.argv[1] == "insert": - while True: - l = sys.stdin.readline() - if not l: break - conn.execute("INSERT INTO records(description) VALUES (?)", (l.rstrip(),)) - conn.commit() - else: - print("Unrecognised command: %s" % sys.argv[1]) http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/db_recv.py ---------------------------------------------------------------------- diff --git a/examples/python/db_recv.py b/examples/python/db_recv.py deleted file mode 100755 index 8c79049..0000000 --- a/examples/python/db_recv.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/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 ApplicationEvent, Container, EventInjector -from db_common import Db - -class Recv(MessagingHandler): - def __init__(self, url, count): - super(Recv, self).__init__(auto_accept=False) - self.url = url - self.delay = 0 - self.last_id = None - self.expected = count - self.received = 0 - self.accepted = 0 - self.db = Db("dst_db", EventInjector()) - - def on_start(self, event): - event.container.selectable(self.db.injector) - e = ApplicationEvent("id_loaded") - e.container = event.container - self.db.get_id(e) - - def on_id_loaded(self, event): - self.last_id = event.id - event.container.create_receiver(self.url) - - def on_record_inserted(self, event): - self.accept(event.delivery) - self.accepted += 1 - if self.accepted == self.expected: - event.connection.close() - self.db.close() - - def on_message(self, event): - id = int(event.message.id) - if (not self.last_id) or id > self.last_id: - if self.received < self.expected: - self.received += 1 - self.last_id = id - self.db.insert(id, event.message.body, ApplicationEvent("record_inserted", delivery=event.delivery)) - print("inserted message %s" % id) - else: - self.release(event.delivery) - else: - self.accept(event.delivery) - -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=0, - 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-j/blob/2f85988e/examples/python/db_send.py ---------------------------------------------------------------------- diff --git a/examples/python/db_send.py b/examples/python/db_send.py deleted file mode 100755 index c07dcc0..0000000 --- a/examples/python/db_send.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/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, unicode_literals -import optparse -import time -try: - import Queue -except: - import queue as Queue - - -from proton import Message -from proton.handlers import MessagingHandler -from proton.reactor import ApplicationEvent, Container, EventInjector -from db_common import Db - -class Send(MessagingHandler): - def __init__(self, url, count): - super(Send, self).__init__() - self.url = url - self.delay = 0 - self.sent = 0 - self.confirmed = 0 - self.load_count = 0 - self.records = Queue.Queue(maxsize=50) - self.target = count - self.db = Db("src_db", EventInjector()) - - def keep_sending(self): - return self.target == 0 or self.sent < self.target - - def on_start(self, event): - self.container = event.container - self.container.selectable(self.db.injector) - self.sender = self.container.create_sender(self.url) - - def on_records_loaded(self, event): - if self.records.empty(): - if event.subject == self.load_count: - print("Exhausted available data, waiting to recheck...") - # check for new data after 5 seconds - self.container.schedule(5, self) - else: - self.send() - - def request_records(self): - if not self.records.full(): - print("loading records...") - self.load_count += 1 - self.db.load(self.records, event=ApplicationEvent("records_loaded", link=self.sender, subject=self.load_count)) - - def on_sendable(self, event): - self.send() - - def send(self): - while self.sender.credit and not self.records.empty(): - if not self.keep_sending(): return - record = self.records.get(False) - id = record['id'] - self.sender.send(Message(id=id, durable=True, body=record['description']), tag=str(id)) - self.sent += 1 - print("sent message %s" % id) - self.request_records() - - def on_settled(self, event): - id = int(event.delivery.tag) - self.db.delete(id) - print("settled message %s" % id) - self.confirmed += 1 - if self.confirmed == self.target: - event.connection.close() - self.db.close() - - def on_disconnected(self, event): - self.db.reset() - self.sent = self.confirmed - - def on_timer_task(self, event): - print("Rechecking for data...") - self.request_records() - -parser = optparse.OptionParser(usage="usage: %prog [options]", - description="Send messages to the supplied address.") -parser.add_option("-a", "--address", default="localhost:5672/examples", - help="address to which messages are sent (default %default)") -parser.add_option("-m", "--messages", type="int", default=0, - help="number of messages to send; 0 sends indefinitely (default %default)") -opts, args = parser.parse_args() - -try: - Container(Send(opts.address, opts.messages)).run() -except KeyboardInterrupt: pass - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/direct_recv.py ---------------------------------------------------------------------- diff --git a/examples/python/direct_recv.py b/examples/python/direct_recv.py deleted file mode 100755 index 1c6bf36..0000000 --- a/examples/python/direct_recv.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/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__() - 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 event.message.id and event.message.id < self.received: - # ignore duplicate message - return - 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: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 - - - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/direct_send.py ---------------------------------------------------------------------- diff --git a/examples/python/direct_send.py b/examples/python/direct_send.py deleted file mode 100755 index 35bd2f5..0000000 --- a/examples/python/direct_send.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/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, unicode_literals -import optparse -from proton import Message -from proton.handlers import MessagingHandler -from proton.reactor import Container - -class Send(MessagingHandler): - def __init__(self, url, messages): - super(Send, self).__init__() - self.url = url - self.sent = 0 - self.confirmed = 0 - self.total = messages - - def on_start(self, event): - self.acceptor = event.container.listen(self.url) - - def on_sendable(self, event): - while event.sender.credit and self.sent < self.total: - 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 - if self.confirmed == self.total: - print("all messages confirmed") - event.connection.close() - self.acceptor.close() - - def on_disconnected(self, event): - self.sent = self.confirmed - -parser = optparse.OptionParser(usage="usage: %prog [options]", - description="Send messages to the supplied address.") -parser.add_option("-a", "--address", default="localhost:5672/examples", - help="address to which messages are sent (default %default)") -parser.add_option("-m", "--messages", type="int", default=100, - help="number of messages to send (default %default)") -opts, args = parser.parse_args() - -try: - Container(Send(opts.address, opts.messages)).run() -except KeyboardInterrupt: pass http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/helloworld.py ---------------------------------------------------------------------- diff --git a/examples/python/helloworld.py b/examples/python/helloworld.py deleted file mode 100755 index 7a91aa4..0000000 --- a/examples/python/helloworld.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/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, unicode_literals -from proton import Message -from proton.handlers import MessagingHandler -from proton.reactor import Container - -class HelloWorld(MessagingHandler): - def __init__(self, server, address): - super(HelloWorld, self).__init__() - self.server = server - self.address = address - - def on_start(self, event): - conn = event.container.connect(self.server) - event.container.create_receiver(conn, self.address) - event.container.create_sender(conn, self.address) - - def on_sendable(self, event): - event.sender.send(Message(body="Hello World!")) - event.sender.close() - - def on_message(self, event): - print(event.message.body) - event.connection.close() - -Container(HelloWorld("localhost:5672", "examples")).run() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/helloworld_blocking.py ---------------------------------------------------------------------- diff --git a/examples/python/helloworld_blocking.py b/examples/python/helloworld_blocking.py deleted file mode 100755 index 5a5ce6d..0000000 --- a/examples/python/helloworld_blocking.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/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 -from proton import Message -from proton.utils import BlockingConnection -from proton.handlers import IncomingMessageHandler - -conn = BlockingConnection("localhost:5672") -receiver = conn.create_receiver("examples") -sender = conn.create_sender("examples") -sender.send(Message(body="Hello World!")); -msg = receiver.receive(timeout=30) -print(msg.body) -receiver.accept() -conn.close() - http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/helloworld_direct.py ---------------------------------------------------------------------- diff --git a/examples/python/helloworld_direct.py b/examples/python/helloworld_direct.py deleted file mode 100755 index 0292abe..0000000 --- a/examples/python/helloworld_direct.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/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, unicode_literals -from proton import Message -from proton.handlers import MessagingHandler -from proton.reactor import Container - -class HelloWorld(MessagingHandler): - def __init__(self, url): - super(HelloWorld, self).__init__() - self.url = url - - def on_start(self, event): - self.acceptor = event.container.listen(self.url) - event.container.create_sender(self.url) - - def on_sendable(self, event): - event.sender.send(Message(body="Hello World!")) - event.sender.close() - - def on_message(self, event): - print(event.message.body) - - def on_accepted(self, event): - event.connection.close() - - def on_connection_closed(self, event): - self.acceptor.close() - -Container(HelloWorld("localhost:8888/examples")).run() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/helloworld_direct_tornado.py ---------------------------------------------------------------------- diff --git a/examples/python/helloworld_direct_tornado.py b/examples/python/helloworld_direct_tornado.py deleted file mode 100755 index a3b017a..0000000 --- a/examples/python/helloworld_direct_tornado.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/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 -from proton import Message -from proton.handlers import MessagingHandler -from proton_tornado import Container - -class HelloWorld(MessagingHandler): - def __init__(self, url): - super(HelloWorld, self).__init__() - self.url = url - - def on_start(self, event): - self.acceptor = event.container.listen(self.url) - event.container.create_sender(self.url) - - def on_sendable(self, event): - event.sender.send(Message(body="Hello World!")) - event.sender.close() - - def on_message(self, event): - print(event.message.body) - - def on_accepted(self, event): - event.connection.close() - - def on_connection_closed(self, event): - self.acceptor.close() - -Container(HelloWorld("localhost:8888/examples")).run() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/helloworld_tornado.py ---------------------------------------------------------------------- diff --git a/examples/python/helloworld_tornado.py b/examples/python/helloworld_tornado.py deleted file mode 100755 index 0781bbb..0000000 --- a/examples/python/helloworld_tornado.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 -from proton import Message -from proton.handlers import MessagingHandler -from proton_tornado import Container - -class HelloWorld(MessagingHandler): - def __init__(self, server, address): - super(HelloWorld, self).__init__() - self.server = server - self.address = address - - def on_start(self, event): - conn = event.container.connect(self.server) - event.container.create_receiver(conn, self.address) - event.container.create_sender(conn, self.address) - - def on_sendable(self, event): - event.sender.send(Message(body="Hello World!")) - event.sender.close() - - def on_message(self, event): - print(event.message.body) - event.connection.close() - -Container(HelloWorld("localhost:5672", "examples")).run() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/README.txt ---------------------------------------------------------------------- diff --git a/examples/python/messenger/README.txt b/examples/python/messenger/README.txt deleted file mode 100644 index c26ba76..0000000 --- a/examples/python/messenger/README.txt +++ /dev/null @@ -1,20 +0,0 @@ -This directory contains example scripts using the messenger API. - - send.py - a simple example of using the messenger API to send messages - recv.py - a simple example of using the messenger API to receive messages - -Note that depending on the address passed into these scripts, you can -use them in either a peer to peer or a brokered scenario. - -For brokered usage: - - recv.py amqp://<broker>/<queue> - - send.py -a amqp://<broker>/<queue> msg_1 ... msg_n - -For peer to peer usage: - - # execute on <host> to receive messages from all local network interfaces - recv.py amqp://~0.0.0.0 - - send.py -a amqp://<host> msg_1 ... msg_n http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/async.py b/examples/python/messenger/async.py deleted file mode 100755 index a1b0292..0000000 --- a/examples/python/messenger/async.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/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 sys -from proton import * - -class CallbackAdapter: - - def __init__(self, messenger): - self.messenger = messenger - self.messenger.blocking = False - self.messenger.outgoing_window = 1024 - self.messenger.incoming_window = 1024 - # for application use - self.message = Message() - self._incoming_message = Message() - self.tracked = {} - - def run(self): - self.running = True - self.messenger.start() - self.on_start() - - while self.running: - self.messenger.work() - self._process() - - self.messenger.stop() - - while not self.messenger.stopped: - self.messenger.work() - self._process() - - self.on_stop() - - def stop(self): - self.running = False - - def _process(self): - self._process_outgoing() - self._process_incoming() - - def _process_outgoing(self): - for t, on_status in list(self.tracked.items()): - status = self.messenger.status(t) - if status != PENDING: - on_status(status) - self.messenger.settle(t) - del self.tracked[t] - - def _process_incoming(self): - while self.messenger.incoming: - t = self.messenger.get(self._incoming_message) - try: - self.on_recv(self._incoming_message) - self.messenger.accept(t) - except: - ex = sys.exc_info()[1] - print("Exception:", ex) - self.messenger.reject(t) - - def send(self, message, on_status=None): - t = self.messenger.put(message) - if on_status: - self.tracked[t] = on_status http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/client.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/client.py b/examples/python/messenger/client.py deleted file mode 100755 index 62fc16e..0000000 --- a/examples/python/messenger/client.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog <addr> <subject>", - description="simple message server") - -parser.add_option("-r", "--reply_to", default="~/replies", - help="address: [amqp://]<domain>[/<name>] (default %default)") - -opts, args = parser.parse_args() - -if len(args) != 2: - parser.error("incorrect number of arguments") - -address, subject = args - -mng = Messenger() -mng.start() - -msg = Message() -msg.address = address -msg.subject = subject -msg.reply_to = opts.reply_to - -mng.put(msg) -mng.send() - -if opts.reply_to[:2] == "~/": - mng.recv(1) - try: - mng.get(msg) - print(msg.address, msg.subject) - except Exception as e: - print(e) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/recv.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/recv.py b/examples/python/messenger/recv.py deleted file mode 100755 index 5771bd7..0000000 --- a/examples/python/messenger/recv.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <addr_1> ... <addr_n>", - description="simple message receiver") -parser.add_option("-c", "--certificate", help="path to certificate file") -parser.add_option("-k", "--private-key", help="path to private key file") -parser.add_option("-p", "--password", help="password for private key file") - -opts, args = parser.parse_args() - -if not args: - args = ["amqp://~0.0.0.0"] - -mng = Messenger() -mng.certificate=opts.certificate -mng.private_key=opts.private_key -mng.password=opts.password -mng.start() - -for a in args: - mng.subscribe(a) - -msg = Message() -while True: - mng.recv() - while mng.incoming: - try: - mng.get(msg) - except Exception as e: - print(e) - else: - print(msg.address, msg.subject or "(no subject)", msg.properties, msg.body) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/recv_async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/recv_async.py b/examples/python/messenger/recv_async.py deleted file mode 100755 index b38c31a..0000000 --- a/examples/python/messenger/recv_async.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/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 sys, optparse -from async import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <addr_1> ... <addr_n>", - description="simple message receiver") - -opts, args = parser.parse_args() - -if not args: - args = ["amqp://~0.0.0.0"] - -class App(CallbackAdapter): - - def on_start(self): - print("Started") - for a in args: - print("Subscribing to:", a) - self.messenger.subscribe(a) - self.messenger.recv() - - def on_recv(self, msg): - print("Received:", msg) - if msg.body == "die": - self.stop() - if msg.reply_to: - self.message.clear() - self.message.address = msg.reply_to - self.message.body = "Reply for: %s" % msg.body - print("Replied:", self.message) - self.send(self.message) - - def on_stop(self): - print("Stopped") - -a = App(Messenger()) -a.run() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/send.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/send.py b/examples/python/messenger/send.py deleted file mode 100755 index c274656..0000000 --- a/examples/python/messenger/send.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/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 sys, optparse -from proton import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", - description="simple message sender") -parser.add_option("-a", "--address", default="amqp://0.0.0.0", - help="address: //<domain>[/<name>] (default %default)") - -opts, args = parser.parse_args() -if not args: - args = ["Hello World!"] - -mng = Messenger() -mng.start() - -msg = Message() -for m in args: - msg.address = opts.address - msg.body = str(m) - mng.put(msg) - -mng.send() -print("sent:", ", ".join(args)) - -mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-proton-j/blob/2f85988e/examples/python/messenger/send_async.py ---------------------------------------------------------------------- diff --git a/examples/python/messenger/send_async.py b/examples/python/messenger/send_async.py deleted file mode 100755 index 50f7a68..0000000 --- a/examples/python/messenger/send_async.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/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 sys, optparse -from async import * - -parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", - description="simple message sender") -parser.add_option("-a", "--address", default="amqp://0.0.0.0", - help="address: //<domain>[/<name>] (default %default)") -parser.add_option("-r", "--reply_to", help="reply_to: //<domain>[/<name>]") - -opts, args = parser.parse_args() -if not args: - args = ["Hello World!"] - -class App(CallbackAdapter): - - def on_start(self): - print("Started") - self.message.clear() - self.message.address = opts.address - self.message.reply_to = opts.reply_to - for a in args: - self.message.body = a - self.send(self.message, self.on_status) - - if opts.reply_to: - self.messenger.recv() - - def on_status(self, status): - print("Status:", status) - if not opts.reply_to or opts.reply_to[0] != "~": - args.pop(0) - if not args: self.stop() - - def on_recv(self, msg): - print("Received:", msg) - if opts.reply_to and opts.reply_to[0] == "~": - args.pop(0) - if not args: self.stop() - - def on_stop(self): - print("Stopped") - -a = App(Messenger()) -a.run() --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
