简体   繁体   中英

MQ Pure Java Client Lib

I am evaluating Websphere MQ7. I am a traditionally a TibRV guy. One thing I do not like is the fact that the IBM java client libs require C++ libs in order to run. Is there anyway to run the IBM java client libs without requiring the C++ libs? eg is there a pure java client library for MQ ?

I have previously written a JMS client to MQSeries v6 (not your version, I know) without needing to install native libs. The only IBM libraries I required were titled:

  • com.ibm.mq-6.jar
  • com.ibm.mqbind.jar
  • com.ibm.mqjms-6.jar

According to this post they come with the client install. I assume you can install it once, then re-use the jars (any licensing issues and expert opinions aside).

EDIT: In response to your comment, here's the client code I hacked up. It is for reading messages from a queue and blatting them to files. It's written in Scala. I hope it helps somewhat.

import com.ibm.mq._
import java.text._
import java.io._

case class QueueDetails(hostname: String, channel: String, 
  port: Int, queueManager: String, queue: String)

class Reader(details: QueueDetails) {
  def read = {
    MQEnvironment.hostname = details.hostname
    MQEnvironment.channel = details.channel
    MQEnvironment.port = details.port
    val props = new java.util.Hashtable[String, String]
    props.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES)
    MQEnvironment.properties = props
    val qm = new MQQueueManager(details.queueManager)
    val options = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE
    val q = qm.accessQueue(details.queue, options, null, null, null)
    val depth = q.getCurrentDepth
    val indexFormat = new DecimalFormat(depth.toString.replaceAll(".", "0"))

    def exportMessage(index: Int): Unit = {
      if (index < depth) {
        val msg = new MQMessage
        q.get(msg, new MQGetMessageOptions)
        val msgLength = msg.getMessageLength
        val text = msg.readStringOfByteLength(msgLength)
        val file = new File("message_%s.txt".format(indexFormat.format(index)))
        val writer = new BufferedWriter(new FileWriter(file))
        writer.write(text)
        writer.close
        println(file.getAbsolutePath)
        exportMessage(index + 1)
      }
    }

    exportMessage(0)
    q.close
    qm.disconnect
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM