JRuby と Open MQ を利用する Cannot resolve external resource into attachment.

このページは翻訳作業中です。

この FAQ にご協力いただける方は、 コントリビューション・ガイドライン をご覧ください。

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.

フィードバックをお寄せ下さい – [^mailto:users@mq.java.net]

Open MQ へ戻る


Jspwiki style: center


以下、 JRuby と Open MQ の利用方法を説明します。

はじめに

JRuby と Open MQ を使い始める前に、以下の準備が必要です:


サンプルアプリケーションの実行手順

  1. JRuby をインストールする
  2. Open MQ をインストールする
  3. 以下の jar ファイルをクラスパスに含める:
    1. .../mq/lib/jms.jar
    2. .../mq/lib/imq.jar
    3. .../mq/lib/imqjmsra.jar (extract from imqjmsra.rar, i.e. jar xvf imqjmsra.rar imqjmsra.jar)
  4. jruby HelloWorldMessage.rb (jruby コマンドでアプリケーションを実行)
$ jruby HelloWorldMessage.rb
Sending Message: Hello World
Read Message: Hello World

HelloWorldMessage.rb (サンプルアプリケーションのソースコード)

#############################################################################
#
# 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

日本語翻訳: Kana

英文 (翻訳したバージョン: 8)