jsparrow
JSparrow is a JMS client based on JRuby. Previously it has been called Sparrow, but changed his name because has another project with the same name.
Install
Make gem install:
sudo gem install jsparrow -s http://gemcutter.org
Example
Five steps to send and receive JMS messages to/from a JMS provider.
WARNING: OpenJMS will be used as JMS provider, but any other could be used with no problems.
1) Create my_jsparrow_test.rb file and require the gems
require 'rubygems'
require 'jsparrow'
2) Setup indispensable informations to connect your JMS provider
JSparrow::Connection.configure do |connection|
connection.use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar'
connection.use_jndi_properties :initial_context_factory => 'org.exolab.jms.jndi.InitialContextFactory',
:provider_url => 'tcp://localhost:3035'
# :security_principal => 'user',
# :security_credentials => 'password'
connection.enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
connection.enable_queues :my_queue => 'MyQueue'
end
3) Create the client and start it
jms_client = JSparrow::Connection.new_client
jms_client.start
4) OK! Now you can send and receive messages right now!
jms_client.queue_sender(:my_queue).('jsparrow rocks!') do |msg|
msg.set_string_property('recipient', 'jsparrow-example')
end
jms_client.queue_receiver(:my_queue).(
:timeout => 5000,
:selector => "recipient = 'jsparrow-example'"
) do |msg|
puts "is text message? #{msg.}" # is text message? true
puts "message: #{msg.text}" # message: jsparrow rocks!
end
5) After you receive your amazing messages, stop the client
jms_client.stop
So, now that you wrote code and save it, start the OpenJMS server, create the queue (MyQueue), and run above script:
jruby my_jsparrow_test.rb
jsparrow rocks! =)
Sample
A very simple sample code
Or, if you don’t want write code, only do it:
jruby sample/sample_queue.rb
Copyright
Copyright © 2009 Leandro Silva (CodeZone) <[email protected]>. See LICENSE for details.