-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.rb
61 lines (48 loc) · 1.51 KB
/
send.rb
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
require 'qpid_proton'
class SendHandler < Qpid::Proton::MessagingHandler
def initialize(conn_url, address, message_number, message_body)
super()
@conn_url = conn_url
@address = address
@expected = message_number
@message_body = message_body
@sent = 0
@confirmed = 0
end
def on_container_start(container)
conn = container.connect(@conn_url)
conn.open_sender(@address)
end
# TODO Manage exceptions
def on_sender_open(sender)
puts "SEND: Opened sender for target address '#{sender.target.address}'\n"
end
def on_sendable(sender)
while sender.credit > 0 && @sent < @expected
# msg = Qpid::Proton::Message.new(contents, { :durable => true, :priority => 8 } )
msg = Qpid::Proton::Message.new
msg.body = @message_body
msg.durable = true
msg.priority = 8
sender.send(msg)
@sent = @sent + 1
puts "Message #{@sent} sent"
end
end
def on_tracker_accept(tracker)
@confirmed = @confirmed + 1
if @confirmed == @expected
puts "All #{@expected} messages confirmed!"
tracker.connection.close
end
end
end
if ARGV.size == 4
conn_url, address, message_number, message_body = ARGV
else
abort "Usage: send.rb <connection-url> <address> <message-number> <message-body>\n"
end
puts "Sending #{message_number} messages to #{conn_url}"
handler = SendHandler.new(conn_url, address, message_number.to_i, message_body)
container = Qpid::Proton::Container.new(handler)
container.run