reidmorrison / rubywmq

Ruby interface into WebSphere MQ
https://github.com/reidmorrison/rubywmq
Apache License 2.0
32 stars 24 forks source link

rubywmq

RubyWMQ is a high performance native Ruby interface into WebSphere MQ.

Project Status

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!

Features

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

Compatibility

WebSphere MQ

Example

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

More Examples

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

Documentation for the RubyWMQ Gem is generated automatically when the gem is installed. It is also available online

Installation

Installing on UNIX/Linux

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

Install RubyWMQ Gem

gem install rubywmq

If no errors appear RubyWMQ is ready for use

Installation Errors

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

Installing on Windows

Install Ruby and DevKit

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 WebSphereMQ

Install the WebSphere MQ Client and/or Server

Install the RubyWMQ Gem

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"'

Installation Errors

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

Verifying the build

Verifying a local WebSphere MQ Server installation

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

Rails Installation

After following the steps above to compile the source code, add the following line to Gemfile

gem 'rubywmq'

Architecture

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.

FAQ

Programs fail with: `require': no such file to load -- wmq (LoadError)

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'

Program fails to connect with MQRC2059, MQRC_Q_MGR_NOT_AVAILABLE

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:

MQ Server Connections (Local Queue Manager)

Possible Configuration Issues:

Is the Queue Manager active?

dspmq

Expected output:
QMNAME(REID)                          STATUS(Running)

MQ Client Connections (Remote Queue Manager)

Possible Client Configuration Issues:

Incorrect Queue Manager Name

On UNIX/Linux, try the following command on the machine running the Queue Manager:

ps -ef | grep runmqlsr

Is the Queue Manager active?

dspmq

Expected output:
QMNAME(REID)                          STATUS(Running)
runmqsc queue_manager_name
dis channel(*) chltype(SVRCONN)

Versioning

This project adheres to Semantic Versioning.

Author

Reid Morrison :: @reidmorrison

Contributors

License

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.