Topic creation in ActiveMQ

Cacheing picture Cacheing · Jul 18, 2012 · Viewed 8.8k times · Source

http://docs.oracle.com/javaee/1.4/api/javax/jms/Session.html#createTopic(java.lang.String) This API says that session.createTopic(topicname) is not for creating the physical topic. What does this mean?

If I want one group of user which has authority of "admin" is responsible for creating topics and another group of user which has authority of "write" is responsible for publishing messages to this topic, how can I implement this? It seems that the latter group must also have the authority of "admin" because they have to use this method: session.createTopic(topicname).

How can I separate the "admin" and "write" authority?

Answer

Jakub Korab picture Jakub Korab · Jul 18, 2012

What the JMS spec means is that createTopic(String) is used to give you a logical handle (javax.jms.Topic, a subtype of Destination) which you can subsequently use in other calls such as createProducer(Destination) or createConsumer(Destination). It just so happens in ActiveMQ that a physical destination will be created at the same time.

If you want to make sure that users can only publish to already created destinations, assign that group read and write permissions, but not admin. Obviously that assumes that those topics already exist - if they do not, then you'll get an exception thrown.

You haven't said exactly how you would like to administer topic creation, but if you are OK with doing that in the ActiveMQ config for them to be created at startup, then define those topics in a destinations block:

<broker xmlns="http://activemq.apache.org/schema/core">
  <destinations>
    <topic physicalName="topic.1" />
    <topic physicalName="topic.2" />
  </destinations>
</broker>