Sha256: 6024e7c40f73294df5ecd9bb58d0ec3033295bafac628a5bbd73b7d95da139dd
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
#!/usr/bin/env jruby # # HornetQ Producer: # Write messages to the queue # require 'rubygems' require 'yaml' require 'hornetq' count = (ARGV[0] || 1).to_i config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml') constants = config['constants'] # Create a HornetQ session HornetQ::Client::Factory.session(config['client']) do |session| session.create_queue(constants[:address], constants[:queue], constants[:durable]) producer = session.create_producer(constants[:address]) start_time = Time.now puts "Sending messages" (1..count).each do |i| message = session.create_message(HornetQ::Client::Message::TEXT_TYPE, true) # Set the message body text message.body = "Message ##{i}" message.put_string_property(Java::org.hornetq.api.core.SimpleString.new(HornetQ::Client::Message::HDR_DUPLICATE_DETECTION_ID.to_s), Java::org.hornetq.api.core.SimpleString.new("uniqueid#{i}")) # Send message to the queue begin producer.send(message) rescue Java::org.hornetq.api.core.HornetQException => e puts "Received producer exception: #{e.message} with code=#{e.cause.code}" if e.cause.code == Java::org.hornetq.api.core.HornetQException::UNBLOCKED puts "Retrying the send" retry end end #puts message puts "#{i}\n" if i%1000 == 0 end duration = Time.now - start_time puts "Delivered #{count} messages in #{duration} seconds at #{count/duration} messages per second" end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jruby-hornetq-0.2.5.alpha | examples/advanced/transaction-failover/producer.rb |