HI;
I'm trying to modify the topic forwarder python script you provided on the website under the title "Middleware plumbing".
I've attached the original code at the bottom of this e-mail for reference;
I'd like to forward from an existing queue to a newly created topic so that I can record and playback the messages.
This is slightly different from creating new queues and topics as in the code sample.
I realize that there's the possibility of "missing" messages which are consumed before Hermes polls the queue, but I'm hoping that it's "good enough" for the job requirement.
It's an existing production system with persistent messaging requirements, so I don't have flexibility to convert the existing JMS queue into a topic.
The idea is to retrieve messages from the queue, but not "commit" my reads. This should leave the messages free to be consumed by the intended system consumer. I then forward the retrieved messages to a topic which I record for test analysis and playback.
1. The python example code as provided doesn't execute in Hermes 1.10. It seem to not properly initialize the "browser" object. I'm hoping that adding browser = hermes.browser.HermesBrowser.getBrowser() and proper imports will do the trick.
2. I can't understand how the provided code creates the connection / session / destination managed objects I'm used to using in JMS. Are "wms" and "emq" javax.jmx.ConnectionFactory objects or JNDIConnectionFactory objects? something else?
3. How can I lookup an existing queue using the ?.?.?connnectionFactory classes?
4. How can I "rollback" my hermesIn.receive() or simply not commit it?
Because its typeless jython, a poor old java programmer like me is a bit lost. I can't quite figure out the class usages from javap, and the javadocs aren't included in the distro.
Any help gratefully appreciated;
Simon
from com.jidesoft.document import DocumentComponent
from com.jidesoft.document import DocumentComponentListener
from hermes.swing import SwingRunner
from javax.swing import JTextArea
from javax.swing import JScrollPane
from java.lang import Runnable
from java.lang import Thread
from javax.jms import MessageListener
from org.apache.log4j import Logger
area = JTextArea()
class Forwarder (Runnable, DocumentComponent, DocumentComponentListener):
def __init__(self):
DocumentComponent.__init__(self, JScrollPane(area), "Message Forwarder")
self.__running = 1
area.setColumns(80)
area.setLineWrap(1)
self.addDocumentComponentListener(self)
area.append("Ready\n")
def run(self):
hermesIn = browser.getContext().lookup("wmq")
hermesOut = browser.getContext().lookup("ems")
inbound = hermesIn.createQueue("MUREX.OUT")
outbound = hermesOut.createTopic("TRADE.CONFIRM")
while self.__running:
message = hermesIn.receive(inbound, 500)
if message != None:
hermesOut.send(outbound, message)
hermesOut.commit()
hermesIn.commit()
area.append(message.toString())
hermesIn.close()
hermesOut.close()
def stop(self):
self.__running = 0
def documentComponentOpened(self, event):
return
def documentComponentClosing(self, event):
return
def documentComponentClosed(self, event):
self.stop()
return
def documentComponentMoving(self, event):
return
def documentComponentMoved(self, event):
return
def documentComponentActivated(self, event):
return
def documentComponentDeactivated(self, event):
return
forwarder = Forwarder()
browser.addDocumentComponent(forwarder)
thread = Thread(forwarder)
thread.start()
