I was preparing a JMS to JMS bridge recently with Mule and wanted to ensure the message and transaction ordering was correct so quickly created a test script that I could run to populate a duable subscription that was being forwarded by Mult to WebSphereMQ. Once Mule had forwaded the messages I can then use Hermes to browse the queue and ensure all messages arrived safely and in the correct order.
hermes = browser.getContext().lookup("localhost-ems")
topic = hermes.createTopic("ABN.GM.FI.CREDIT.TRADE")
for i in range(100):
message = hermes.createTextMessage("foobar")
message.setIntProperty("counter", i)
hermes.send(topic, message)
hermes.commit()
hermes.close()
print "messages sent"
A variation of this is loading messages you have previously saved in the jms2xml.xsd schema from HermesJMS. In this example we also slow down the rate of sending messages to one per second:
from time import sleep
from java.io import File
from java.io import FileInputStream
hermes = browser.getContext().lookup("EMS")
queue = hermes.createQueue("sample")
file = File("c:/messages.xml")
istream = FileInputStream(file)
messages = hermes.fromXML(istream)
for m in messages:
hermes.send(queue, m)
hermes.commit()
print "message sent"
sleep(1)
hermes.close()
print "all messages sent"