forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Sparrow
alexbcoles edited this page Jan 6, 2011
·
1 revision
Sparrow (http://github.com/leandrosilva/sparrow) is a very simple JMS client for messaging application based on JRuby.
Add Github as a source for your RubyGem:
gem sources -a http://gems.github.com
Make install:
sudo gem install leandrosilva-sparrow
WARNING: OC4J will be used as Java EE application server, but any other could be used with no problems.
Create a file named my_sparrow_test.rb and put the script below:
require 'rubygems' require 'sparrow' # Initial setup (that has to be done once) jms_client = Sparrow::JMS::Connection::Client.new do |props| props.client_jar_file = '/oc4j_extended_101330/j2ee/home/oc4jclient.jar' props.initial_context_factory = 'oracle.j2ee.naming.ApplicationClientInitialContextFactory' props.provider_url = 'ormi://localhost:23791' props.security_principal = 'oc4jadmin' props.security_credentials = 'welcome' end jms_client.enable_connection_factories( :queue_connection_factory => 'jms/MyQueueCF' ) jms_client.enable_queues( :my_queue => 'jms/MyQueue' ) # Send message jms_client.queue_sender(:my_queue).send_text_message('sparrow rocks!') do |msg| msg.set_string_property('recipient', 'sparrow-example') end # Receive message jms_client.queue_receiver(:my_queue).receive_message( :timeout => 5000, :selector => "recipient = 'sparrow-example'" ) do |msg| puts msg.is_text_message? # true puts msg.text # sparrow rocks! end
So, now start the OC4J server, create the connection factory (jms/MyQueueCF) and queue (jms/MyQueue), and run above script:
jruby my_sparrow_test.rb
Output:
sparrow rocks! =)
- Executar JRuby a partir do Java (pt_BR) Article about integration of Java with JRuby, showing how running JRuby code from Java.