Sha256: 29efcef36675d935bd6bb75287e84b461f0c2ad6fd61ee15c3507f10ab086e75

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 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.start('hornetq://invm') do |server|
  # Allow a CTRL-C to stop this process
  server.enable_shutdown_on_signal

  HornetQ::Client::Connection.start_session('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.body = "#{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

6 entries across 6 versions & 1 rubygems

Version Path
jruby-hornetq-0.5.0.alpha examples/simple/invm.rb
jruby-hornetq-0.4.0 examples/simple/invm.rb
jruby-hornetq-0.3.3 examples/simple/invm.rb
jruby-hornetq-0.3.2 examples/simple/invm.rb
jruby-hornetq-0.3.1 examples/simple/invm.rb
jruby-hornetq-0.3.0.alpha examples/simple/invm.rb