reidmorrison / rubywmq

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

Error connecting to Queue Manager:XXXX, reason:MQRC_SSL_INITIALIZATION_ERROR[2393] #15

Closed kiranps closed 8 years ago

kiranps commented 8 years ago

Here is my code

require 'wmq'

wait_seconds = 30

WMQ::QueueManager.connect(q_mgr_name: 'XXXXX',
                          connection_name: 'XXXXXXX',
                          channel_name: 'XXXXX',
                          transport_type: WMQ::MQXPT_TCP,
                          ssl_cipher_spec: 'TRIPLE_DES_SHA_US',
                          key_repository: '/path/to/key',
                          trace_level: 3) do |reply_queue|
  qmgr.open_queue(
    q_name:         'XXXXXXX',
    dynamic_q_name: 'REQUEST.*',
    mode:           :input
  ) do |reply_queue|

    message            = WMQ::Message.new()
    message.descriptor = {
      msg_type:       WMQ::MQMT_REQUEST,
      reply_to_q:     reply_queue.name,
      reply_to_q_mgr: qmgr.name,
      format:         WMQ::MQFMT_STRING,
      expiry:         wait_seconds*10 # Measured in tenths of a second
    }
    message.data       = 'Hello World'

    # Send request message
    qmgr.put(q_name: 'XXXXX', message: message)

    # Copy outgoing Message id to correlation id
    message.descriptor[:correl_id] = message.descriptor[:msg_id]

    # Wait for reply
    #   Only get the message that matches the correlation id set above
    if reply_queue.get(wait: wait_seconds * 1000, message: message, match: WMQ::MQMO_MATCH_CORREL_ID)
      puts 'Received:'
      puts message.data
    else
      # get returns false when no message received. Also: message.data = nil
      puts 'Timed Out waiting for a reply from the server'
    end
  end
end

Trace logs

WMQ::QueueManager#initialize() Queue Manager:XXXX
WMQ::QueueManager#connect() Loading MQ Client Library:libmqic_r.so
WMQ::QueueManager#connect() MQ Library:libmqic_r.so Loaded successfully
WMQ::QueueManager#connect() MQ API's loaded successfully
WMQ::QueueManager#connect() Connect to Queue Manager:XXXXXX
WMQ::QueueManager#connect() MQCONNX completed with reason:MQRC_SSL_INITIALIZATION_ERROR[2393], Handle:-1
request.rb:5:in `connect': WMQ::QueueManager#connect(). Error connecting to Queue Manager:XXXX, reason:MQRC_SSL_INITIALIZATION_ERROR[2393] (WMQ::WMQException)
        from request.rb:5:in `<main>'
WMQ::QueueManager Freeing QUEUE_MANAGER structure
WMQ::QueueManager#gc() Releasing MQ Library
reidmorrison commented 8 years ago

Unfortunately their is no easy answer for SSL support, I have never used SSL before, nor tested it before. Maybe someone in the community has been able to get it to work with SSL?

My suggestion would be to get one of the sample C programs that ships with IBM MQ working using SSL. Once we have that in place we can determine what special code is needed for the C api to work with SSL.

kiranps commented 8 years ago

@reidmorrison Thank you, I will look in too it

kiranps commented 8 years ago

@reidmorrison

when i checked AMQERR01.LOG i got the following error

The remote end of channel 'XXXXX.XXX.SVRCONN' on host 'XXXXXXX' has had
a CipherSpec error. The channel did not start.
ACTION:
Review the error logs on the remote system to discover the problem with the
CipherSpec.

In the following thread a user had a same issue when ssl is enabled. he forgot to define MQCD_VERSION in his C Program.

http://www.mqseries.net/phpBB2/viewtopic.php?t=56360&sid=dce302ecf5dc67a71b86f81a65742dd1

In my case the sample program for ssl (amqssslc.c) shipped with websphere works fine. In that program the following code sets the MQCD_VERSION. I'm using Websphere MQ 7.5

    if (pCipherSpec != NULL)
    {
      /* SSL requires MQCD version 7 or later */
      ClientConn.Version = MQCD_VERSION_7;

      /* The MQCD must contain the SSL CipherSpec string */
      strncpy(ClientConn.SSLCipherSpec,
              pCipherSpec,
              MQ_SSL_CIPHER_SPEC_LENGTH);

      printf("Using SSL CipherSpec %s\n", pCipherSpec);
    }

since we had same issue MQRC_SSL_INITIALIZATION_ERROR[2393]. I looked into wmq_queue_manager.c, but i didn't understood how rubywmq defines MQCD_VERSION_7

reidmorrison commented 8 years ago

This change is a significant amount of effort, including having to setup MQ with SSL to test it. If you want to pay for this feature, we can add it for you. Or, if you add the capability yourself, please send a pull request.

The place to start is in wmq_queue_manager.c and look for the MQSCO. The current code does not support ssl_cipher_spec, but if you search for key_repository you will find the location where to specify ssl_cipher_spec.

arif-muhammad-wmc-tech commented 8 years ago

I got the same issue.

WMQ::QueueManager#initialize() Queue Manager:EBNGWQ WMQ::QueueManager#connect() Loading MQ Client Library:libmqic_r.so WMQ::QueueManager#connect() MQ Library:libmqic_r.so Loaded successfully WMQ::QueueManager#connect() MQ API's loaded successfully WMQ::QueueManager#connect() Connect to Queue Manager:EBNGWQ WMQ::QueueManager#connect() MQCONNX completed with reason:MQRC_SSL_INITIALIZATION_ERROR[2393], Handle:-1

arif-muhammad-wmc-tech commented 8 years ago

Any progress on this issue?

reidmorrison commented 8 years ago

As mentioned above, we need someone that is running a SSL setup to submit a PR so that we can fix this issue. Anyone want to help out?

arif-muhammad-wmc-tech commented 8 years ago

As an alternative can we use jruby-jms with SSL setup ?

reidmorrison commented 8 years ago

Yes, jruby-jms should work, but it requires JRuby.

JRuby is an excellent solution in enterprise environments since it can leverage the existing Java investment and it has real threads without global locks. Java can call JRuby directly to embed Ruby code in Java apps. With JRuby an entire Rails app can be deployed as a war file on existing Java App servers.

arif-muhammad-wmc-tech commented 8 years ago

Thanks. If an existing Rails app is running with Ruby 2 and the requirement is to integrate the WebSphere MQ functionality with SSL setup in background job like Sidekiq then how the jruby jms will work?

reidmorrison commented 8 years ago

For better scalability, batch performance, and priority based processing I recommend Rocket Job over Sidekiq. It directly supports both Ruby 2 and JRuby.

arif-muhammad-wmc-tech commented 8 years ago

Ok thanks. In case we want to use Sidekiq, does it support both Ruby 2 and JRuby?

reidmorrison commented 8 years ago

Closing since RubyWMQ does not support SSL connections.