Search code examples
pythonjmsjythonweblogic12cwlst

Weblogic: Import messages to a Uniform Distributed Queue from exported xml file using WLST


I am trying to write a script to import messages to a Uniform Distributed queue in Weblogic using WLST but I am unable to find a solution that specifically caters to my requirement.

Let me explain the requirement:

I have error queues that store failed messages. I have exported them as an xml file (using WLST) and segregated them based on the different error code in message header into smaller xml files which need to be imported into the main queue for reprocessing(not using Admin console).

I am sure that there is something that can be done to achieve this as I am able to import the segregated xml files using the import option in Admin console which works like a charm but have no idea how it is actually being done so that it could be implemented as a script.

I have explored a few options like exporting the files as a binary SER file which works but it is not something that can be used to filter out the retryable messages only.

The wlst method importMessages() only accepts a composite datatype array. Any method to convert/create the required composite Datatype array from the xml files would also be a great solution to the issue.


Solution

  • I agree it is not very simple and intuitive. You have 2 solutions :

    • pure WLST code
    • java code using JMS API

    If you want to write pure WLST code here is a code sample that will help you. The code creates and publish n messages into a queue. The buildJMSMessage() function is responsible to create a text message.

    from javax.management.openmbean import CompositeData
    from weblogic.jms.extensions import JMSMessageInfo, JMSMessageFactoryImpl
    
    ...
    
    def buildJMSMessage(text):
    
        handle = 1
        state = 1
        XidString = None
        sequenceNumber = 1
        consumerID = None
        wlmessage = JMSMessageFactoryImpl.getFactory().createTextMessage(text)
    
        destinationName = ""
        bodyIncluded = True
        msg = JMSMessageInfo(handle, state, XidString, sequenceNumber, consumerID, wlmessage, destinationName, bodyIncluded)
    
        return msg
    
    
    
    ....
    
    quanity = 10
    messages = jarray.zeros(quantity,CompositeData)
    
    for i in range(0,quantity):
        messages[i] = buildJMSMessage('Test message #'+str(i)).toCompositeData()
        i = i + 1
    
    queue.importMessages(messages, False)