Debian Codegraph @

bin/stompcat

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # Copyright 2006 LogicBlaze Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 begin; require 'rubygems'; rescue; end
18 require 'stomp'
19
20 #
21 # This simple script is inspired by the netcat utility. It allows you to receive
22 # data from a stomp destination and output it.
23 #
24 # Usage: stompcat (destination-name)
25 #
26 # Example: stompcat /topic/foo
27 # Would display output that arrives at the /topic/foo stomp destination
28 #
29 begin
30
31 if ARGV[0] == '-h' || ARGV[0] == '--help'
32 $stdout.puts
33 $stdout.puts 'Usage: stompcat DESTINATION'
34 $stdout.puts
35 $stdout.puts 'Receives data from a stomp destination and outputs it to STDOUT'
36 $stdout.puts
37 $stdout.puts 'Example: stompcat /topic/foo'
38 $stdout.puts
39 $stdout.puts 'Defaults:'
40 $stdout.puts "DESTINATION\t/topic/default"
41 $stdout.puts "STOMP_HOST\tlocalhost"
42 $stdout.puts "STOMP_PORT\t61613"
43 $stdout.puts "STOMP_USER\t"
44 $stdout.puts "STOMP_PASSWORD\t"
45 $stdout.puts
46 $stdout.puts 'You can override the host, port, user, or password through environment variables'
47 exit 0
48 end
49
50 @port = 61613
51 @host = "localhost"
52 @user = ENV["STOMP_USER"];
53 @password = ENV["STOMP_PASSWORD"]
54
55 @host = ENV["STOMP_HOST"] if ENV["STOMP_HOST"] != nil
56 @port = ENV["STOMP_PORT"] if ENV["STOMP_PORT"] != nil
57
58 @destination = "/topic/default"
59 @destination = $*[0] if $*[0] != nil
60
61 $stderr.print "Connecting to stomp://#{@host}:#{@port} as #{@user}\n"
62 @conn = Stomp::Connection.open(@user, @password, @host, @port, true)
63 $stderr.print "Getting output from #{@destination}\n"
64
65 @conn.subscribe(@destination, { :ack =>"client" })
66 while true
67 @msg = @conn.receive
68 $stdout.print @msg.body
69 $stdout.flush
70 @conn.ack @msg.headers["message-id"]
71 end
72
73 rescue
74 end
75