Jsparrow
JSparrow is a JMS client based on JRuby
Install / Use
/learn @leandrosilva/JsparrowREADME
= 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.
I'm sorry but any time I break backward compatibility. However, always is for make a better API.
=== 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.
- Create my_jsparrow_test.rb file and require the gems
require 'rubygems' require 'jsparrow'
- Setup indispensable informations to connect your JMS provider
JSparrow::Connection.configure do use_jms_client_jar '/opt/openjms/lib/openjms-0.7.7-beta-1.jar'
use_jndi_properties :initial_context_factory => 'org.exolab.jms.jndi.InitialContextFactory',
:provider_url => 'tcp://localhost:3035'
# :security_principal => 'user',
# :security_credentials => 'password'
enable_connection_factories :queue_connection_factory => 'ConnectionFactory'
enable_queues :my_queue => 'MyQueue'
end
- Create the client and start it
jms_client = new_jsparrow_client jms_client.start
- OK! Now you can send and receive messages right now!
jms_client.queue_sender(:my_queue).send_text_message('jsparrow rocks!') do |msg| msg.set_string_property('recipient', 'jsparrow-example') end
jms_client.queue_receiver(:my_queue).receive_message( :timeout => 5000, :selector => "recipient = 'jsparrow-example'" ) do |msg|
puts "is text message? #{msg.is_text_message?}" # is text message? true
puts "message: #{msg.text}" # message: jsparrow rocks!
end
- 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
=== Next
For more informations, read the specs! ;)
http://github.com/leandrosilva/jsparrow/tree/master/spec
== Copyright
Copyright (c) 2009 Leandro Silva (CodeZone) leandrodoze@gmail.com. See LICENSE for details.
