-
1. Re: Queue can not be created at runtime
ataylor Mar 30, 2010 7:51 AM (in response to pnranjith)Ranjith PN wrote:
I need to get 4 queues which are created at runtime. How can I create queues at Runtime. I can not specify the queue name in its configuration file.
Is there any simple implementation as in ActiveMQ ?
take a look at the management section of the user manual and also the management example.
-
2. Re: Queue can not be created at runtime
timfox Mar 30, 2010 7:58 AM (in response to ataylor)Or just use createQueue on the core API.
But the short answer is RTFM! There are several ways of doing this with HornetQ
-
3. Re: Queue can not be created at runtime
pnranjith Mar 30, 2010 8:21 AM (in response to timfox)I have read the manual. But couldn't get hold of entire thing. Can you please give me the snippet which returns a queue dynamically.
-
4. Re: Queue can not be created at runtime
jbmuser Mar 30, 2010 8:58 AM (in response to pnranjith)JMSServerControl control = getServerControl(getMBeanServerConnection(host, jmxPort));
boolean status = control.createQueue(queueName, queueName);private JMSServerControl getServerControl(MBeanServerConnection mbsc) throws Exception{
ObjectName name=new ObjectName("org.hornetq:module=JMS,type=Server");
return (JMSServerControl)MBeanServerInvocationHandler.newProxyInstance(mbsc,name,JMSServerControl.class,false);
}public MBeanServerConnection getMBeanServerConnection(String host, String jmxPort) throws IOException{
String jmxUrl = "service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi";
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(jmxUrl), new HashMap());
conn = connector.getMBeanServerConnection();
return conn;
} -
5. Re: Queue can not be created at runtime
pnranjith Mar 30, 2010 9:42 AM (in response to jbmuser)I did as you said. Now I am getting the following exception:
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.tt.q.Reader.getMBeanServerConnection(Reader.java:90)
at com.tt.q.Reader.start(Reader.java:69)
at com.tt.db.DbWriter.<init>(DbWriter.java:102)
at com.tt.db.DbWriter.init(DbWriter.java:135)
at com.tt.Relay2.main(Relay2.java:65)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
... 6 more
Caused by: java.rmi.NoSuchObjectException: no such object in table
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
... 11 more -
6. Re: Queue can not be created at runtime
ataylor Mar 30, 2010 10:55 AM (in response to pnranjith)That looks like an jndi classloader ssue, nothing to do with HornetQ. The AS guys would help u better there, altho i bet if you google you will find other people have had the same problem
-
7. Re: Queue can not be created at runtime
timfox Mar 30, 2010 10:58 AM (in response to ataylor)You don't need to use JMX to create queues.
In HornetQ there are four ways you can create queues
1) By declaring them in xml config
2) By using the management interface via JMX
3) By using the management interface via a connection by sending messages to a special management address
4) By using the createQueue method on the core session interface
All of this is described in the user manual.
-
8. Re: Queue can not be created at runtime
pnranjith Mar 30, 2010 2:52 PM (in response to timfox)But I need a queue instance as I am migrating from ActiveMQ to HornetQ. Otherwise it will make me to reqrite entire producer and consumer logic.
Is there any way which returns a queue. Or any techniq to get the created queue instance?
-
9. Re: Queue can not be created at runtime
jbmuser Mar 30, 2010 11:47 PM (in response to pnranjith)Once you create a queue using JMX as I mentioned above, call session.createQueue(queueName);. That will return you the Queue instance
-
10. Re: Queue can not be created at runtime
pnranjith Mar 31, 2010 1:46 AM (in response to jbmuser)Thank you.
But I am getting the following exception. Do you have any clue?
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:338)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.tt.q.Reader.getMBeanServerConnection(Reader.java:90)
at com.tt.q.Reader.start(Reader.java:69)
at com.tt.db.DbWriter.<init>(DbWriter.java:102)
at com.tt.db.DbWriter.init(DbWriter.java:135)
at com.tt.Relay2.main(Relay2.java:65)
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1886)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
... 6 more -
11. Re: Queue can not be created at runtime
richardspeter Mar 31, 2010 2:55 AM (in response to pnranjith)Hi Ranjith,
I am also getting the same kind of Exception when I am trying to connect.
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
Did you find a way out?
Is this due to the JMXServiceURL mistake?
I specified it as service:jmx:rmi:///jndi/rmi://localhost:1098/jmxrmi. Is there any configuration in hornetq config files for this object registration or is any prior registration required?
Richards Peter.
-
12. Re: Queue can not be created at runtime
jmesnil Mar 31, 2010 4:05 AM (in response to richardspeter)Richards Peter wrote:
Hi Ranjith,
I am also getting the same kind of Exception when I am trying to connect.
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.NoSuchObjectException: no such object in table]
Did you find a way out?
Is this due to the JMXServiceURL mistake?
I specified it as service:jmx:rmi:///jndi/rmi://localhost:1098/jmxrmi. Is there any configuration in hornetq config files for this object registration or is any prior registration required?
Richards Peter.
With this URL, you hit HornetQ RMI server used by JNDI but the JMX Server is not bound to it.
Remote connections to JMX are not enabled by default for security reasons: http://hornetq.sourceforge.net/docs/hornetq-2.0.0.GA/user-manual/en/html/management.html#management.jmx.configuration. See Java Management guide to enable it at the JVM level.
HornetQ's jmx example shows how to configure the JVM to connect remotely to JMX.
-
13. Re: Queue can not be created at runtime
pnranjith Mar 31, 2010 5:12 AM (in response to jmesnil)Thanks Bijith. It works now.
I had to configure the rmi server with remote access
This link was helpful in doing that
Also I tried with jconsole to connect with the server first before running my program.
-
14. Re: Queue can not be created at runtime
timfox Mar 31, 2010 5:18 AM (in response to pnranjith)Ranjith PN wrote:
Thanks Bijith. It works now.
I had to configure the rmi server with remote access
This link was helpful in doing that
Also I tried with jconsole to connect with the server first before running my program.
This is also clearly describe in the user manual:
And also we ship with a fully working example which demonstrates exactly how to do this.
But of course it's too much to expect anyone to actually read the documentation or look at the examples
BTW, like I mentioned before. JMX is not the only way you can create a queue programmatically in HornetQ, you can just use the connection if you want.