-
1. Re: Dynamic topic creation in a client app.
trosenbaum Oct 31, 2002 11:31 AM (in response to stevejenks)The JMS spec says that topic and queue
creation (except for TemporaryTopic and
TemporaryQueue) is outside the scope
of the spec. Creation of "permanent"
topics and queues is an administrative
task. I'm pretty sure that there are JBoss
ways to perform such administrative tasks
from your program, but I can't tell you how
to do it (because I don't know how myself:).
The createTopic method allows you to create
an object representing an already-existing Topic
only. You can create a TemporaryTopic using the
JMS API -- perhaps that will suffice for your needs. -
2. Re: Dynamic topic creation in a client app.
tharrisx Nov 12, 2002 2:32 AM (in response to stevejenks)
import javax.jms.*;
import javax.management.*;
import javax.naming.*;
import org.jboss.jmx.adaptor.rmi.*;
... From class members ...
private InitialContext _jndiContext = null;
...
... From constructor ...
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://192.168.2.2:1099/");
_jndiContext = new InitialContext(env);
...
private Topic getOrCreateTopic(String name) throws EventTransportException {
Topic endResult = null;
System.out.println("EventTransportJBossJMSImpl: Trying to acquire topic '" + name + "'...");
try {
try {
endResult = (Topic)_jndiContext.lookup("topic/" + name);
System.out.println("EventTransportJBossJMSImpl: Found existing topic '" + name + "'.");
return endResult;
} catch(NamingException ne) {
System.out.println("EventTransportJBossJMSImpl: Creating new topic '" + name + "'...");
RMIAdaptor jmxAccess = (RMIAdaptor)_jndiContext.lookup("jmx/rmi/RMIAdaptor");
ObjectName objName = new ObjectName("jboss.mq:service=DestinationManager");
String[] signature = {"java.lang.String"};
Object[] arguments = {name};
Object result = jmxAccess.invoke(objName, "createTopic", arguments, signature);
endResult = (Topic)_jndiContext.lookup("topic/" + name);
System.out.println("EventTransportJBossJMSImpl: New topic '" + name + "' was created.");
return endResult;
}
} catch(Exception e) {
throw new EventTransportException(e);
}
} -
3. Re: Dynamic topic creation in a client app.
tharrisx Nov 12, 2002 2:32 AM (in response to stevejenks)
import javax.jms.*;
import javax.management.*;
import javax.naming.*;
import org.jboss.jmx.adaptor.rmi.*;
... From class members ...
private InitialContext _jndiContext = null;
...
... From constructor ...
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://192.168.2.2:1099/");
_jndiContext = new InitialContext(env);
...
private Topic getOrCreateTopic(String name) throws EventTransportException {
Topic endResult = null;
System.out.println("EventTransportJBossJMSImpl: Trying to acquire topic '" + name + "'...");
try {
try {
endResult = (Topic)_jndiContext.lookup("topic/" + name);
System.out.println("EventTransportJBossJMSImpl: Found existing topic '" + name + "'.");
return endResult;
} catch(NamingException ne) {
System.out.println("EventTransportJBossJMSImpl: Creating new topic '" + name + "'...");
RMIAdaptor jmxAccess = (RMIAdaptor)_jndiContext.lookup("jmx/rmi/RMIAdaptor");
ObjectName objName = new ObjectName("jboss.mq:service=DestinationManager");
String[] signature = {"java.lang.String"};
Object[] arguments = {name};
Object result = jmxAccess.invoke(objName, "createTopic", arguments, signature);
endResult = (Topic)_jndiContext.lookup("topic/" + name);
System.out.println("EventTransportJBossJMSImpl: New topic '" + name + "' was created.");
return endResult;
}
} catch(Exception e) {
throw new EventTransportException(e);
}
} -
4. Re: Dynamic topic creation in a client app.
tesuji Jan 7, 2004 7:18 AM (in response to stevejenks)This is exactly what I need. However when I try the solution given by tharrisx I get a "NameNotFoundException: jmx not bound"
Do I need to do something to make the lookup of jmx/rmi/RMIAdapter to work?
Is there some step I need to do prior to the given example to bind JMX?
Any help would be greatly appreciated. -
5. Re: Dynamic topic creation in a client app.
adrian.brock Jan 7, 2004 2:29 PM (in response to stevejenks)It might not be bound at the location given in 3.0.3
I wouldn't recommend using jbossmq in 3.0.3 there are too many
memory leaks in that version.
Use 3.0.8
Regards,
Adrian