12 Replies Latest reply on Nov 12, 2002 2:30 AM by Thomas J. Harris

    How to create a new Topic

    Michael Schulze Newbie

      Hi everybody!

      Unfortunately I did´nt manage to find the place, where I can create a new Topic and an new TopicConnectionFactory. My Application runs well under the reference-Server by SUN, but now...

      Can anyone help me? Would be really kind!

      Thanks in advance,
      Michael

        • 1. Re: How to create a new Topic
          Adrian Brock Master

          Look at
          jbossmq-service.xml
          and
          jbossmq-destinations-service.xml

          Regards,
          Adrian

          • 2. Re: How to create a new Topic
            Thomas J. Harris Newbie

            Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

            private Topic getOrCreateTopic(String name) throws EventTransportException {
                Topic endResult = null;
                try {
                    try {
                        endResult = (Topic)_jndiContext.lookup("topic/" + name);
                        return endResult;
                    } catch(NamingException ne) {
                        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);
                        return endResult;
                    }
                } catch(Exception e) {
                    throw new EventTransportException(e);
                }
            }

            Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

            Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

            Tom Harris

            • 3. Re: How to create a new Topic
              Thomas J. Harris Newbie

              Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

              private Topic getOrCreateTopic(String name) throws EventTransportException {
                  Topic endResult = null;
                  try {
                      try {
                          endResult = (Topic)_jndiContext.lookup("topic/" + name);
                          return endResult;
                      } catch(NamingException ne) {
                          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);
                          return endResult;
                      }
                  } catch(Exception e) {
                      throw new EventTransportException(e);
                  }
              }

              Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

              Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

              Tom Harris

              • 4. Re: How to create a new Topic
                Thomas J. Harris Newbie

                Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                private Topic getOrCreateTopic(String name) throws EventTransportException {
                    Topic endResult = null;
                    try {
                        try {
                            endResult = (Topic)_jndiContext.lookup("topic/" + name);
                            return endResult;
                        } catch(NamingException ne) {
                            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);
                            return endResult;
                        }
                    } catch(Exception e) {
                        throw new EventTransportException(e);
                    }
                }

                Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                Tom Harris

                • 5. Re: How to create a new Topic
                  Thomas J. Harris Newbie

                  Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                  private Topic getOrCreateTopic(String name) throws EventTransportException {
                      Topic endResult = null;
                      try {
                          try {
                              endResult = (Topic)_jndiContext.lookup("topic/" + name);
                              return endResult;
                          } catch(NamingException ne) {
                              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);
                              return endResult;
                          }
                      } catch(Exception e) {
                          throw new EventTransportException(e);
                      }
                  }

                  Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                  Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                  Tom Harris

                  • 6. Re: How to create a new Topic
                    Thomas J. Harris Newbie

                    Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                    private Topic getOrCreateTopic(String name) throws EventTransportException {
                        Topic endResult = null;
                        try {
                            try {
                                endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                return endResult;
                            } catch(NamingException ne) {
                                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);
                                return endResult;
                            }
                        } catch(Exception e) {
                            throw new EventTransportException(e);
                        }
                    }

                    Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                    Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                    Tom Harris

                    • 7. Re: How to create a new Topic
                      Thomas J. Harris Newbie

                      Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                      private Topic getOrCreateTopic(String name) throws EventTransportException {
                          Topic endResult = null;
                          try {
                              try {
                                  endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                  return endResult;
                              } catch(NamingException ne) {
                                  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);
                                  return endResult;
                              }
                          } catch(Exception e) {
                              throw new EventTransportException(e);
                          }
                      }

                      Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                      Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                      Tom Harris

                      • 8. Re: How to create a new Topic
                        Thomas J. Harris Newbie

                        Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                        private Topic getOrCreateTopic(String name) throws EventTransportException {
                            Topic endResult = null;
                            try {
                                try {
                                    endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                    return endResult;
                                } catch(NamingException ne) {
                                    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);
                                    return endResult;
                                }
                            } catch(Exception e) {
                                throw new EventTransportException(e);
                            }
                        }

                        Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                        Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                        Tom Harris

                        • 9. Re: How to create a new Topic
                          Thomas J. Harris Newbie

                          Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                          private Topic getOrCreateTopic(String name) throws EventTransportException {
                              Topic endResult = null;
                              try {
                                  try {
                                      endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                      return endResult;
                                  } catch(NamingException ne) {
                                      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);
                                      return endResult;
                                  }
                              } catch(Exception e) {
                                  throw new EventTransportException(e);
                              }
                          }

                          Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                          Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                          Tom Harris

                          • 10. Re: How to create a new Topic
                            Thomas J. Harris Newbie

                            Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                            private Topic getOrCreateTopic(String name) throws EventTransportException {
                                Topic endResult = null;
                                try {
                                    try {
                                        endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                        return endResult;
                                    } catch(NamingException ne) {
                                        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);
                                        return endResult;
                                    }
                                } catch(Exception e) {
                                    throw new EventTransportException(e);
                                }
                            }

                            Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                            Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                            Tom Harris

                            • 11. Re: How to create a new Topic
                              Thomas J. Harris Newbie

                              Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method:

                              private Topic getOrCreateTopic(String name) throws EventTransportException {
                                  Topic endResult = null;
                                  try {
                                      try {
                                          endResult = (Topic)_jndiContext.lookup("topic/" + name);
                                          return endResult;
                                      } catch(NamingException ne) {
                                          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);
                                          return endResult;
                                      }
                                  } catch(Exception e) {
                                      throw new EventTransportException(e);
                                  }
                              }

                              Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                              Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                              Tom Harris

                              • 12. Re: How to create a new Topic
                                Thomas J. Harris Newbie

                                Topics and Queues in JBoss are normally configured statically in the xml files mentioned above. But, there is a way to dynamically add and remove topics, using the JMX interface. Take a look at this method and the rest of the code fragment:

                                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);
                                }
                                }


                                Now, just ignore the bad prototype-like exception handling for a moment and look at the use of the jmxAccess RMIAdaptor from instantiation to the invoke method call. That's how you add a Topic. Removal is just the same, but you use the "removeTopic" method instead of the "createTopic" method. There are ones for Queues too.

                                Now, what I'm interested in doing is creating a topic hierarchy, such that a topic "X.Y.Z" could be published to, and subscribers could get messages published to that topic with subscription topics like "X.*.Z" or "X.>" That's key to our use of a JMS server, and I haven't been able to find any information that even remotely comes close to describing how JBoss Topics can be grouped or used in tandem. Anyone have any links for me?

                                Tom Harris