Sha256: d6d7cecb533d5dbc4b66a8a2e7050d236e9915f9da4f32491d5ac222f7ed28a5

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

#
# HornetQ Producer:
#          Write messages to the queue
#

# Allow examples to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'rubygems'
require 'yaml'
require 'hornetq'

count = (ARGV[0] || 1).to_i
config = YAML.load_file(File.dirname(__FILE__) + '/hornetq.yml')['development']

# Create a HornetQ session
HornetQClient::Factory.create_session(config) do |session|
  #session.create_queue('Example', 'Example', true)
  producer = session.create_producer('jms.queue.ExampleQueue')
  start_time = Time.now

  puts "Sending messages"
  (1..count).each do |i|
    message = session.create_message(HornetQClient::Message::TEXT_TYPE,false)
    # Set the message body text
    message << "#{Time.now}: ### Hello, World ###"
    # Send message to the queue
    producer.send(message)
    #puts message
    puts "#{i}\n" if i%1000 == 0
    puts "Durable" if message.durable
  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.0.alpha examples/producer.rb