我只是试图改造一个JMS持久订阅者,我正在使用HornetQ服务器。但是我在执行时抛出了以下异常
Connection Factory Looked Up : HornetQConnectionFactory [serverLocator=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost], discoveryGroupConfiguration=null], clientID=null, consumerWindowSize = 1048576, dupsOKBatchSize=1048576, transactionBatchSize=1048576, readOnly=false]
Topic Looked Up : HornetQTopic[TestTopic]
Connection Created : org.hornetq.jms.client.HornetQConnection@299320cf
CLient ID set : DSubCliID
Session Created : HornetQSession->DelegatingSession [session=ClientSessionImpl [name=ab3a1be5-559f-11e3-bd5b-87d0be06d2c5, username=null, closed=false, factory = ClientSessionFactoryImpl [serverLocator=ServerLocatorImpl [initialConnectors=[TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost], discoveryGroupConfiguration=null], connectorConfig=TransportConfiguration(name=netty, factory=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory) ?port=5445&host=localhost, backupConfig=null], metaData=(jms-client-id=DSubCliID,jms-session=,)]@22eff179]
javax.jms.JMSSecurityException: HQ119032: User: null doesnt have permission=CREATE_DURABLE_QUEUE on address {2}
at org.hornetq.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:388)
at org.hornetq.core.client.impl.ClientSessionImpl.internalCreateQueue(ClientSessionImpl.java:2021)
at org.hornetq.core.client.impl.ClientSessionImpl.createQueue(ClientSessionImpl.java:357)
at org.hornetq.core.client.impl.DelegatingSession.createQueue(DelegatingSession.java:298)
at org.hornetq.jms.client.HornetQSession.createConsumer(HornetQSession.java:782)
at org.hornetq.jms.client.HornetQSession.createDurableConsumer(HornetQSession.java:547)
at org.hornetq.jms.client.HornetQSession.createDurableConsumer(HornetQSession.java:527)
at DurableSubscriber.main(DurableSubscriber.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: HornetQSecurityException[errorType=SECURITY_EXCEPTION message=HQ119032: User: null doesnt have permission=CREATE_DURABLE_QUEUE on address {2}]
... 13 more
看起来有些权限问题。除了在hornetq-jms.xml中添加默认队列和主题外,我没有更改任何配置。
<queue name="TestQueue">
<entry name="queues/TestQueue"/>
</queue>
<topic name="TestTopic">
<entry name="topics/TestTopic"/>
</topic>
hornetq-configuration.xml
中的安全配置如下 -
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="send" roles="guest"/>
</security-setting>
</security-settings>
一切都是默认的。必须做些什么才能创建一个持久的用户?
答案 0 :(得分:7)
默认配置中缺少createDurableQueue
权限角色映射,请查看HornetQ
持久订阅者示例代码(与安装捆绑在一起)以进行所需配置。
简而言之,您可以尝试使用其他配置:
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
答案 1 :(得分:1)
只是添加上面的苛刻答案,这是正确答案BTW我们也可以完全禁用安全性。
添加行
<security-enabled>false</security-enabled>
到hornetq-configuration.xml
并完全删除<security-settings>
也可以解决问题。
更多信息here。
答案 2 :(得分:1)
请勿忘记将用户与&#34; guest&#34;将消息发送到队列时的角色。为此,您需要编辑application-roles.properties并设置
sender_user =客