Skip navigation


Frequently when publishing a message we want to surface some properties from the XML message into the JMS header so subscribers can efficiently filter the messages they receive.

This example uses XPath expressions to pull data out of the message and into the JMS header.

from org.jaxen.dom import DOMXPath 
from org.apache.axis.utils import XMLUtils 
from java.io import File
from java.io import FileInputStream

hermes = browser.getContext().lookup("HornetQ") 
context = hermes.createContext() 
topic = context.lookup("topic/All_EU_Deals") 
context.close() 

dir = File("c:/local/example_messages")

systemIdXPath = DOMXPath("/notification/notificationHeader/originatingSystemID") 
dealTypeXPath = DOMXPath("/notification/deal/dealHeader/dealType")
dealStatusXPath = DOMXPath("/notification/deal/dealHeader/dealStatus")

for file in dir.listFiles():
    istream = FileInputStream(file)
    document = XMLUtils.newDocument(istream)
    message = hermes.createTextMessage(XMLUtils.DocumentToString(document))
    message.setStringProperty("DEAL_TYPE", dealTypeXPath.stringValueOf(document))
    message.setStringProperty("SOURCE", systemIdXPath.stringValueOf(document))
    message.setStringProperty("DEAL_STATUS", dealStatusXPath.stringValueOf(document))
    hermes.send(topic, message)
    istream.close()
    hermes.commit()
hermes.close()

Note that for this to work I had to add jaxen-1.1.1.jar, axis-1.4.jar, j2ee.jar and commons-discovery-0.2.jar to the Java class path in either hermes.bat or hermes.sh

Adaptavist Theme Builder Powered by Atlassian Confluence