How to publish message to IBM WebsphereMQ TOPIC using rubywmq gem - ruby

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:
IBM WMQ Server & Client v7.5
Ruby v2.3.0
rubywmq v2.1.1

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.

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)

Related

Rabbitmq set name for webstomp / stompjs temporary queues

I just wanted to ask if it is possible to specify the name for the temporary auto-delete queues, which are bound to the destination when I subscribe to a webstomp queue/exchange.
The reason is, that I would like to specify a fine graded JWT permission control, so I would like to give permission f.e. to "stomp-subscriptions-user123-abcde" and therefore I would like to call the temporary queue name not "stomp-subscription-randomstring", but "stomp-subscriptions-user123-randomstring".
Is this possible?
I looked through the available documentation, but couldn't find anything (only the name of the subscription id, but not of the temporary queue name).
Documentation: https://stomp-js.github.io/
Here is the source code for the function that generates a queue name:
https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbitmq_stomp/src/rabbit_stomp_util.erl#L368-L382
Notice that it only auto-generates a name if the x-queue-name header is NOT present. So, it looks like you can specify whatever name you'd like via that header. Here is the documentation for it:
https://www.rabbitmq.com/stomp.html#d.ugqn
NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

How to specify flow control parameters in PubSubTemplate?

I am using pull method to pull the messages out of my pubsub subscription as specified https://docs.spring.io/spring-cloud-gcp/docs/current/reference/html/#pull-methods, I see option to set max number of messages but don't see a way to specify the flow control params like max-outstanding-element-count and max-outstanding-request-bytes as in https://docs.spring.io/spring-cloud-gcp/docs/current/reference/html/#publishersubscriber-configuration
By debugging, i see 20MB is set to max-outstanding-request-bytes (screenshot) though it says DEFAULT_FLOW_CONTROL_SETTING should have 100MB https://github.com/googleapis/java-pubsub/blob/main/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java#L456
is there a way so that i can specify that value? I need to use PubSubTemplate with pull method!
Spring Boot: 2.3.5.RELEASE
spring-cloud-gcp-starter-pubsub: 2.0.7
Thanks

Services.AddTransient() Vs Services.AddBot()

In the latest bot samples, we can see that bot is being added to services collection as below
services.AddTransient<IBot, MyBot>();
but in older samples, we saw below approach
services.AddBot<MyBot>(options => { });
Here I am trying to understand the benefits of adding bot using AddTransient() over using AddBot().
What I know is that internally AddBot uses AddTransient only, then why use AddTransient. Referred remarks section from this link.
You can see in the source code that the AddBot methods are used for automatically adding a bot adapter to DI in addition to the bot and for configuring bot-related options like credentials and error handling. The conventions for using the Bot Builder v4 SDK were very different when those samples were made, and the bot's configuration along with its credentials were loaded from something called a bot file. The current convention for using the SDK is much easier because it takes advantage of ASP.NET Core automatically loading the app's configuration from appsettings.json. Since we're not using AddBot anymore you'll notice that the adapter is added to DI explicitly, and you can configure things like error handling and middleware either by accessing the properties and methods of the adapter directly or by deriving your own adapter class, as seen in the samples.

How to parse RSS feeds with Spring Integration when pubDate not available?

I run into a problem parsing RSS feeds with spring-integration-feed. I followed the example at
https://spring.io/guides/gs/integration/
My feeds do not include a published date. According to the RSS specifications, the dates are not required.
As the pubDate is null, the entry is not added to the queue of SyndEntry. See FeedEntryMessageSource.java
Is there a workaround for this?
The FeedEntryMessageSource uses that to detect new entries, without it, you'd get all the entries on every poll.
The only work-around would be a custom message source - you can invoke it from an inbound channel adapter.
If you have a proposal for another mechanism to detect new posts, feel free to open an improvement JIRA Issue.

extract the filename from MQ Message header

Iam using Websphere MQ V8.
I need to get the filename from the header in incoming message file. Is there any properties or default methods available to get it.
Sample File:
The file ame you show in the non-hex dump of your message was put there by the sending application. You should ask the sending application how it was put in there, so that you can know how to pull it out.
Alternatively, show the hex version of your message as well and we might be able to help you further. All the important stuff is not visible to us in your screen shot.
That looks like an RFH version 1 header (not RFH2) but as Morag said, we need to see a hex dump of the message. There are lots of tools to see the hex dump of the message. i.e. amqsbcg, MO71, MQ Visual Edit, etc...
From the manual:
The RFH header guidelines only allow for a single header to exist in a message. The fixed binary set of properties is followed by a variable set of name/value pairs.
strucid
version
struclength
encoding
codedcharsetid
format
flags
namevaluestring
The filename is in the "namevaluestring" section and as Morag said, you need to have a discussion with the sending application to understand the format they used.
Finally, if this is a new sending application being developed then tell the developer to NOT use RFH version 1 but rather message properties.

Resources