Sha256: 628e7bad01ce771167e73b52dfa6fe798dbc33e8ff525a97daec55e5275cf6c9

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

#
# HornetQ In VM Producer and consumer:
#   Example of how to produce and consume messages with the same Java VM
#

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

require 'rubygems'
require 'hornetq'

# Create and start an InVM HornetQ server instance
HornetQ::Server::Factory.start('hornetq://invm') do |server|
  # Allow a CTRL-C to stop this process
  server.enable_shutdown_on_signal

  HornetQ::Client::Factory.start('hornetq://invm') do |session|
    session.create_queue("MyAddress","MyQueue", nil, false)
  
    producer = session.create_producer('MyAddress')
    consumer = session.create_consumer('MyQueue')
  
    # Create a non-durable message to send
    message = session.create_message(HornetQ::Client::Message::TEXT_TYPE,false)
    message << "#{Time.now}: ### Hello, World ###"
  
    producer.send(message)
  
  
    # Receive a single message, return immediately if no message available
    if message = consumer.receive_immediate
      puts "Received:[#{message.body}]"
      message.acknowledge
    else
      puts "No message found"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-hornetq-0.2.1.alpha examples/client/invm.rb