RubyWMQ is a high performance native Ruby interface into WebSphere MQ.
RubyWMQ is no longer under active development. Pull Requests for new features / bug fixes will be accepted though. Anyone interested in taking over development of RubyWMQ can contact me directly.
Note: IBM MQSeries encryption is not supported. Pull requests with this feature are welcome!
The Ruby WMQ interface currently supports the following features:
High performance
Full support for the entire MQ Administration interface (MQAI)
Full support for all WebSphere MQ Headers
Conforms with the Ruby way. Implements:
Relatively easy interface for reading or writing messages
Single Ruby WMQ auto-detection library that concurrently supports:
Includes latest client connection options such as SSL
Tested with WebSphere MQ V5.3, V6, V7, V7.5, and V8
Is written in C to ensure easier portability and performance
WebSphere MQ
require 'wmq'
# Connect to a local queue manager called 'TEST' and put a single message
# on the queue 'TEST.QUEUE'
WMQ::QueueManager.connect(q_mgr_name: 'TEST') do |qmgr|
qmgr.put(q_name: 'TEST.QUEUE', data: 'Hello World')
end
The examples below are all available at https://github.com/reidmorrison/rubywmq/tree/master/examples
Put one message to a Queue (Without opening the queue)
Put messages to a Queue
Read one message from a queue
Reading Several messages from a Queue:
Connect using MQ Client connection
Put Messages to a Queue as a group
Put Messages to a Queue, including message headers
Writing multiple files to a queue, where each file is a separate message:
Writing the contents of a queue to multiple files, where each message is a separate file:
Sample “client” and “server” side applications for sending or processing requests
Documentation for the RubyWMQ Gem is generated automatically when the gem is installed. It is also available online
Install a 'C' Compiler, GNU C++ is recommended
Install Ruby using the package manager for your platform
Also install RubyGems and ruby-dev or ruby-sdk packages if not already installed
Install the WebSphere MQ Client and/or Server
Develop on WebSphere MQ Advanced at no charge!
Note: Install the Development Toolkit (SDK) and Client
Install RubyWMQ Gem
gem install rubywmq
If no errors appear RubyWMQ is ready for use
Use this command to find the directory in which the gems are installed
gem env
When WebSphere MQ is not installed in the default location, call the build command directly and supply the location explicitly:
ruby extconf.rb --with-mqm-include=/opt/mqm/inc --with-mqm-lib=/opt/mqm/lib
make
For platforms such as AIX and HP-UX it may be necessary to statically link in the WebSphere MQ client library when the auto-detection build above does not work. This build option is a last resort since it will only work using a client connection
ruby extconf_client.rb --with-mqm-include=/opt/mqm/inc --with-mqm-lib=/opt/mqm/lib
make
Download and install the Ruby installer from http://rubyinstaller.org/downloads/
Download and install the Development Kit from the same site
Open a command prompt and run the commands below:
cd c:\DevKit
ruby dk.rb init
If you experience any difficulties, see https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
Install the WebSphere MQ Client and/or Server
Develop on WebSphere MQ Advanced at no charge!
Note: Install the Development Toolkit (SDK) and Client
call "c:\DevKit\devkitvars.bat"
gem install rubywmq
If WebSphere MQ is installed in the non-default location:
gem install rubywmq --platform=ruby -- '--with-mqm-include="C:\Program Files\IBM\WebSphere MQ\Tools\c\include"'
Use this command to find the directory in which the gems are installed
gem which rubywmq
The path to the rubywmq gem will be something like
C:\Ruby22\lib\ruby\gems\2.2.0\gems\rubywmq-2.0.3\ext
When WebSphere MQ is not installed in the default location, change to the directory above and call the build command directly while supplying the location explicitly:
call "C:\DevKit\devkitvars.bat"
ruby extconf.rb --with-mqm-include="C:\Program Files\IBM\WebSphere MQ\Tools\c\include"
nmake
Create a local Queue Manager called TEST. Select the option to create the server side channels.
Create a local queue called TEST.QUEUE
Run the following Ruby Code in an irb session:
require 'wmq'
WMQ::QueueManager.connect(:q_mgr_name=>'TEST') do |qmgr|
qmgr.put(:q_name=>'TEST.QUEUE', :data => 'Hello World')
end
After following the steps above to compile the source code, add the following line to Gemfile
gem 'rubywmq'
RubyWMQ uses an automatic detection library to figure out whether a Client or Server is installed locally. This prevents issues with having to statically link with both the client and server libraries and then having to select the "correct" one on startup.
Additionally, this approach allows RubyWMQ to be simultaneously connected to a local Queue Manager via server bindings and to a remote Queue Manager using Client bindings.
Instead of hard coding all the MQ C Structures and return codes into RubyWMQ, it parses the MQ 'C' header files at compile time to take advantage of all the latest features in new releases.
After successfully installing RubyWMQ using the command “gem install rubywmq”, program fails with output similar to the following:
rubywmq-0.3.0/tests/test.rb:4:in `require': no such file to load -- wmq (LoadError)
from rubywmq-0.3.0/tests/test.rb:4
Answer: Add the following line to the top of your Ruby program
require 'rubygems'
When connecting to either a local or remote WebSphere MQ Queue Manager, a very common error returned is that the Queue Manager is not available. This error can occur under any of the following circumstances:
Possible Configuration Issues:
Is the Queue Manager active?
dspmq
Expected output:
QMNAME(REID) STATUS(Running)
Possible Client Configuration Issues:
Incorrect host name
Incorrect port number
Incorrect Channel Name
For example, the channel being used does not exist on the remote Queue Manager.
Note: The channel name is case-sensitive
Incorrect Queue Manager Name
:q_mgr_name is optional for Client Connections. It does however ensure that the program connects to the expected Queue Manager.
For example when the wrong Queue Manager listener is now running on the expected port.
Is the MQ listener program running on the port supplied above?
On UNIX/Linux, try the following command on the machine running the Queue Manager:
ps -ef | grep runmqlsr
The Queue Mananger name and port number should be displayed
If no port number is specified on the command line for an instance of runmqlsr, it means that it is using port 1414.
Is the Queue Manager active?
dspmq
Expected output:
QMNAME(REID) STATUS(Running)
Check if the Channel being used is still defined on the Queue Manager
On the machine running the Queue Manager, run the following commands (may need to run them under the 'mqm' userid):
runmqsc queue_manager_name
dis channel(*) chltype(SVRCONN)
This project adheres to Semantic Versioning.
Reid Morrison :: @reidmorrison
Copyright 2006 - 2015 J. Reid Morrison
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.