Reputation: 215
I'm trying to use rubywmq gem to publish message to a IBM MQ pub/sub topic. I do not see any direct way of publishing to topic from Ruby code.
Following is the MQ TOPIC, SUB setup MQSC:
DEFINE TOPIC(MY_TOPIC) TOPICSTR('COM/APP')
DEFINE QALIAS(MY_TOPIC_Q) TARGET(MY_TOPIC) TARGTYPE(TOPIC)
DEFINE QLOCAL(APP.RAW.INPUT)
DEFINE QLOCAL(APP.VALIDATOR.INPUT)
DEFINE QLOCAL(APP.ENRICHER.INPUT)
DEFINE QLOCAL(APP.XFORM.INPUT)
DEFINE QLOCAL(APP.LOGGER.INPUT)
DEFINE SUB(SUB.APP.RAW.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/RAW') DEST(APP.RAW.INPUT)
DEFINE SUB(SUB.APP.VALIDATOR.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/XML') DEST(APP.VALIDATOR.INPUT)
DEFINE SUB(SUB.APP.ENRICHER.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/VLD') DEST(APP.ENRICHER.INPUT)
DEFINE SUB(SUB.APP.XFORM.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/ENR') DEST(APP.XFORM.INPUT)
DEFINE SUB(SUB.APP.LOGGER.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('#') DEST(APP.LOGGER.INPUT)
I also tried publishing to alias queue for the topic with MQRFH2 header Ruby Code:
WMQ::QueueManager.connect(:connection_name => conn_name, :channel_name => channel_name, :q_mgr_name=> queue_manager) do |qmgr|
message = WMQ::Message.new
message.data = 'Hello World'
message.headers = [
{
header_type: :rf_header_2,
xml: ['<route>COM/APP/MSG/RAW</route>']
}
]
message.descriptor[:format] = WMQ::MQFMT_STRING
qmgr.put(q_name: 'MY_TOPIC_Q', message: message )
end
And then add a SUB with selector like:
DEFINE SUB(SUB.APP.RAW.INPUT) TOPICOBJ(MY_TOPIC) TOPICSTR('MSG/RAW') DEST(APP.RAW.INPUT) PSPROP(RFH2) SELECTOR('route = ''COM/APP/MSG/RAW''')
Couldn't succeed. Could anyone please point where the problem is or suggest an alternative? Thanks.
Software Version Used:
Upvotes: 3
Views: 667
Reputation: 10652
The QALIAS must point to a TOPIC object specific to the TOPICSTR you want to publish to. Example:
DEFINE TOPIC(MY_TOPIC_MSG_RAW) TOPICSTR('COM/APP/MSG/RAW')
DEFINE QALIAS(MY_TOPIC_Q) TARGET(MY_TOPIC_MSG_RAW) TARGTYPE(TOPIC)
Upvotes: 2
Reputation: 31832
Putting a message to an alias over a topic is a method to convert point-to-point apps to pub/sub. Since the API call is PUT and not PUBLISH, there is no mechanism to add a topic string to the prefix supplied by the topic object. The messages are published to the topic string as defined in the topic object and no further. Your SUB.APP.LOGGER.INPUT
subscription should be seeing the publications, but not the other ones.
There are several other issues in the posted code. The crafting of an RFH2 header suggests you are relying on docs from perhaps as early as v5.3 or v6. Unfortunately, there is no mention of which version the MQ server is at or which version client libraries are being used by Ruby.
There is also no mention of what you meant by "Couldn't succeed." Does that mean you saw zero publications, even on SUB.APP.LOGGER.INPUT
pub appeared to PUT messages OK? Or the PUT returned a bad reason code? Or that you got messages on SUB.APP.LOGGER.INPUT
but nowhere else?
For debugging purposes, you can use MQ Explorer, the amqsput
sample, or any of the other supplied tools to drop a message onto the alias queue and look for output. The difference between that test and your Ruby testing should help diagnose the issue.
Please do come back and update your question with additional details if you'd like a less speculative response.
Upvotes: 3