Debian Codegraph @

assembly/src/release/examples/stomp/perl/publisher

raw
1 #!/usr/bin/perl
2 # ------------------------------------------------------------------------
3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ------------------------------------------------------------------------
18 #
19 # sample publisher
20 #
21
22 use strict;
23 use warnings;
24 use Net::STOMP::Client;
25 use Time::HiRes qw(time);
26
27 our(%Option, $Conn, $Start);
28
29 $Option{user} = $ENV{ACTIVEMQ_USER} || "admin";
30 $Option{password} = $ENV{ACTIVEMQ_PASSWORD} || "password";
31 $Option{host} = $ENV{ACTIVEMQ_HOST} || "localhost";
32 $Option{port} = $ENV{ACTIVEMQ_PORT} || 61613;
33 $Option{destination} = $ENV{STOMP_DESTINATION} || "/topic/event";
34 $Option{count} = $ENV{STOMP_COUNT} || 10000;
35
36 $Conn = Net::STOMP::Client->new(
37 host => $Option{host},
38 port => $Option{port},
39 );
40 $Conn->connect(
41 login => $Option{user},
42 passcode => $Option{password},
43 );
44 printf("connected to %s:%d\n", $Conn->peer()->addr(), $Conn->peer()->port());
45 $Start = time();
46 foreach (1 .. $Option{count}) {
47 $Conn->send(
48 destination => $Option{destination},
49 persistent => "false",
50 body => "Hello world from Perl",
51 );
52 }
53 $Conn->send(
54 destination => $Option{destination},
55 persistent => "false",
56 body => "SHUTDOWN",
57 );
58 printf("sent %d messages in %.3f seconds\n", $Option{count}+1, time()-$Start);
59 $Conn->disconnect();