To identify xsd xml messages received from MQ

In IBM MQ, I have a requirement where I can get many xml types from a queue. Xml messages will correspond to the xsd already specified (they say 5 xsd - this means that I can get 5 different xml). When I receive a message from the queue, I would like to know the type of xml (if its xsd1 or xsd2 or so on)

The reason I would like to know is to use the JaxB interface with the SAX implementation, for which I need to provide a java object corresponding to the xml parameter. Therefore, I need to know which xsd is input and is, and assign the appropriate parameter.

The options I have is to set the property in the message header, but the side that discards the message in MQ is not ready.

What other options do I have? Can I get the file name (from xml) from mq and find xsd based on the file name? Or do I need to parse sax and determine the root tag and get the type xsd? Any other best option that you have in mind?

+6
source share
2 answers

Think of MQ as a post office. When you receive a letter, the post office does not interfere with anything inside (payload), and if it changes the look, it only changes the routing information. If you want to sort incoming mail for different recipients, then someone who sends it must put data against which sorting criteria act on the outside of the envelope. If this does not work, you should open the envelope and see the name of the recipient, department or something else on the papers inside.

Your MQ message is an envelope. Sorting criteria can be different queue names, a message property, a message header property, or something in the payload. But if the sender does not explicitly specify the name of the destination queue based on the selection criteria or does not set the message or header property, the only option is to check the payload and understand it.

If you need to check the payload, this is the perfect scenario for IBM Integration Broker. But you can also write an application to perform this function. Very often this is done by the Dispatch application, which receives the message, determines where it goes, then puts it in another queue and COMMIT GET and PUT operations. But if the distribution application needs to parse XML to determine the correct queue, the message must be parsed twice — once by the dispatcher, once by the application.

+2
source

I think you can do:

Does the incoming message have a file name at the beginning of the message body? In this case, after receiving the message, your application can read the first few bytes to get the file name. Based on the file name, the application can use the appropriate Xsd and convey the entire text of the message.

+1
source

Source: https://habr.com/ru/post/983923/


All Articles