有些Topic和Queue需要相應的權限才能操作。
Topic和Queue的權限設定可以在</jboss-4.2.2.GA/server/messaging/deploy/jboss-messaging.sar/destinations-service.xml>中看到
name="jboss.messaging.destination:service=Topic,name=testTopic"
xmbean-dd="xmdesc/Topic-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
<attribute name="SecurityConfig">
<security>
<role name="guest" read="true" write="true"/>
<role name="publisher" read="true" write="true" create="false"/>
<role name="durpublisher" read="true" write="true" create="true"/>
</security>
</attribute>
</mbean>
如果沒有設定security,則使用</jboss-4.2.2.GA/server/messaging/deploy/jboss-messaging.sar/messaging-service.xml>中默認的設定。
<security>
<role name="guest" read="true" write="true" create="true"/>
</security>
</attribute>
如果想操作一個有Security的Queue或者Topic,可以使用Spring的UserCredentialsConnectionFactoryAdapter。在Spring中的設定如下:
jndi-name="ConnectionFactory">
<jee:environment>
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
</jee:environment>
</jee:jndi-lookup>
<bean id="myConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"
lazy-init="true">
<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<bean id="jmsTemplate" lazy-init="true" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="myConnectionFactory" />
<property name="defaultDestinationName" value="A" />
</bean>