Skip navigation


Middleware Plumbing

This bit of python acts as a forwarder between a queue and a topic on different transports. Perhaps you need to do this as part of a test scenario you're building or even have some dire production emergency.

The class will create a new document panel on which it will print each message as its forwarded. Note how the sessions are committed outbound first as this avoids message loss.

This is an example of something you may use for testing or development but never in production unless you really know what you are doing and can deal with any side affects.

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()

Adaptavist Theme Builder Powered by Atlassian Confluence