views:

73

answers:

0

I have Java programs running on various machines (A) that should send messages via server (B) to Flex clients running on other machines (C). The server is running a Grails (Java) application on Tomcat with standalone ApacheMQ and the whole setup is currently working nicely using GraniteDS to communicate between Grails and Flex. (The way GraniteDS works is that the Grails app receives the JMS messages and relays them to the Flex client.)

The problem is that I need to create JMS topics at runtime. GraniteDS relies on the standard Flex services-config.xml file where I define my JMS Topics. Additionally I define the Topics as JNDI resources in Tomcat's Context.xml. Both of these files are static.

The questions are, therefore:

  1. Is there a way to define destinations at runtime for GraniteDS/Flex instead of having them in services-config.xml?
  2. Is there a way to define Tomcat's JNDI Resources at runtime instead of in Context.xml?
  3. Am I going about this the right way; could I avoid using JNDI altogether perhaps?

An answer to any of these questions would be great; it made more sense to me to give you the whole picture instead of splitting them up.

To give a bit more idea here is a section of my services-config.xml, in this case the topic is "discussion".

<destination-jndi-name>java:comp/env/jms/discussion</destination-jndi-name>
<initial-context-environment>
  <property>
    <name>Context.PROVIDER_URL</name>
    <value>tcp://localhost:61616</value>
  </property>
  <property>
    <name>Context.INITIAL_CONTEXT_FACTORY</name>
    <value>org.apache.activemq.jndi.ActiveMQInitialContextFactory</value>
  </property>
</initial-context-environment>

Example section of Context.xml

<Resource name="jms/discussion"
  type="org.apache.activemq.command.ActiveMQTopic" 
  description="Discussion topic for GraniteDS" 
  factory="org.apache.activemq.jndi.JNDIReferenceFactory"
  physicalName="discussion" />