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
|
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'stomp'
if Kernel.respond_to?(:require_relative)
require_relative("./stomp_common")
else
$LOAD_PATH << File.dirname(__FILE__)
require "stomp_common"
end
include Stomp1xCommon
#
# Used primarily for testing performance when sending/receiving "large" messages.
# "large" => YMMV
#
class FilePutGet
# Initialize.
def initialize
@qname = dest()
end
# Run put part of example.
def doput()
puts
puts "pgf001 - put starts"
start_time = Time.now.to_f
fname = ARGV[0]
puts "pgf002: File Name: #{fname}"
file = open(fname, "r")
rs = Time.now.to_f
buff = file.read
re = Time.now.to_f
ppt = sprintf("%22.8f", re - rs)
puts "pgf003: File size: #{buff.respond_to?(:bytesize) ? buff.bytesize : buff.length} bytes"
puts "pgf004: File read time: #{ppt} seconds"
file.close
#
conn = get_connection()
puts "pgf005: Qname is: #{@qname}"
# Try to gracefully handle files that exceed broker size limits.
ph = {:persistent => true}
ph['suppress_content_length'] = 'yes' if suppresscl()
puts "pgf006: Headers are: #{ph.inspect}"
begin
conn.publish(@qname, buff, ph)
rescue
puts "pgf900: exception on publish: #{$!}"
raise
end
conn.disconnect()
end_time = Time.now.to_f
ppt = sprintf("%22.8f", end_time - start_time)
puts "pgf007: File publish time: #{ppt} seconds"
end
# Run get part of example.
def doget()
puts
puts "pgf101 - get starts"
start_time = Time.now.to_f
conn = get_connection()
uuid = conn.uuid() # uuid for Stomp::Connection is a public method
conn.subscribe(@qname, {'id' => uuid}) # Subscribe
msg = conn.receive()
puts "pgf102: Message Command: #{msg.command}"
puts "pgf103: Message Headers: #{msg.headers}"
body_length_bytes = msg.body.respond_to?(:bytesize) ? msg.body.bytesize : msg.body.length
puts "pgf104: Received: #{body_length_bytes} bytes"
#
end_time = Time.now.to_f
ppt = sprintf("%22.8f", end_time - start_time)
puts "pgf105: File receive time: #{ppt} seconds"
conn.disconnect()
end
end
#
e = FilePutGet.new()
e.doput()
# e.doget()
|