File: client.pl

package info (click to toggle)
qpid-proton 0.14.0-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,632 kB
  • ctags: 20,083
  • sloc: java: 39,624; ansic: 29,389; python: 16,581; cpp: 11,250; ruby: 6,618; perl: 2,641; php: 1,033; xml: 957; sh: 230; pascal: 52; makefile: 32
file content (105 lines) | stat: -rwxr-xr-x 2,354 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/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