Using JRuby and Open MQ Cannot resolve external resource into attachment.If you are interested in contributing to this FAQ, please read the Contribution Guidelines. Please note that these samples are posted for the benefit of the community. These samples are intended to help you understand how you can use Open MQ in various integration and application settings. Use of these samples is at your own risk. The following illustrates how you can use JRuby and Open MQ. Getting StartedBefore you begin, you'll need the following:
Steps to run the example application
$ jruby HelloWorldMessage.rb Sending Message: Hello World Read Message: Hello World |
############################################################################# # # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 2000-2008 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common Development # and Distribution License ("CDDL") (collectively, the "License"). You may # not use this file except in compliance with the License. You can obtain # a copy of the License at https://glassfish.java.net/public/CDDL+GPL.html # or mq/legal/LICENSE.txt. See the License for the specific language # governing permissions and limitations under the License. # # When distributing the software, include this License Header Notice in each # file and include the License file at mq/legal/LICENSE.txt. Sun designates # this particular file as subject to the "Classpath" exception as provided by # Sun in the GPL Version 2 section of the License file that accompanied this # code. If applicable, add the following below the License Header, with the # fields enclosed by brackets [] replaced by your own identifying information: # "Portions Copyrighted [year] [name of copyright owner]" # # Contributor(s): # # If you wish your version of this file to be governed by only the CDDL or # only the GPL Version 2, indicate your decision by adding "[Contributor] # elects to include this software in this distribution under the [CDDL or GPL # Version 2] license." If you don't indicate a single choice of license, a # recipient has the option to distribute your version of this file under # either the CDDL, the GPL Version 2 or to extend the choice of license to # its licensees as provided above. However, if you add GPL Version 2 code # and therefore, elected the GPL Version 2 license, then the option applies # only if the new code is made subject to such option by the copyright holder. # # # @(#)HelloWorldMessage.rb 1.0 11/06/08 # ############################################################################# # # The HelloWorldMessage.rb consists only of a main method, which sends # a message to a queue and then receives the message from the queue. # require "java" # Import the JMS API classes. include_class "javax.jms.Session" include_class "com.sun.messaging.ConnectionFactory" include_class "com.sun.messaging.Queue" class HelloWorldMessage def run # Instantiate a Sun Message Queue ConnectionFactory myConnFactory = ConnectionFactory.new # Create a connection to the Sun Message Queue Message service myConn = myConnFactory.createConnection() # Create a session within the connection mySess = myConn.createSession(false, Session::AUTO_ACKNOWLEDGE) # Instantiate a System Message Queue Destination myQueue = Queue.new("world") # Create a message producer myMsgProducer = mySess.createProducer(myQueue) # Create and send a message to the queue myTextMsg = mySess.createTextMessage() myTextMsg.setText("Hello World") puts "Sending Message: " + myTextMsg.getText() myMsgProducer.send(myTextMsg) # Create a message consumer myMsgConsumer = mySess.createConsumer(myQueue) # Start the Connection myConn.start() # Receive a message from the queue txtMsg = myMsgConsumer.receive() # Retreive the contents of the message puts "Read Message: " + txtMsg.getText() # Close the session and connection resources mySess.close() myConn.close() end end helloApp = HelloWorldMessage.new helloApp.run