Jms 远程ActiveMQ队列的Wildfly内部jndi绑定

Jms 远程ActiveMQ队列的Wildfly内部jndi绑定,jms,wildfly,Jms,Wildfly,我能够使用在使用Wildfly 10中定义的资源适配器成功地从远程ActiveMQ队列读取数据。它在单机版中引用以下配置 <subsystem xmlns="urn:jboss:domain:resource-adapters:2.0"> <resource-adapters> <resource-adapter id="activemq-rar.rar"> <module slot="main" id="org.ap

我能够使用在使用Wildfly 10中定义的资源适配器成功地从远程ActiveMQ队列读取数据。它在单机版中引用以下配置

<subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">  
  <resource-adapters>  
    <resource-adapter id="activemq-rar.rar">  
      <module slot="main" id="org.apache.activemq.ra" />  
      <transaction-support>XATransaction</transaction-support>  
        <config-property name="UseInboundSession">  
          false  
        </config-property>  
        <config-property name="Password">  
          mypassword
        </config-property>  
        <config-property name="UserName">  
          myuser  
        </config-property>  
        <config-property name="ServerUrl">  
          ssl://hostname:61617
        </config-property>  
        <connection-definitions>  
          <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory">  
            <xa-pool>  
            <min-pool-size>1</min-pool-size>  
            <max-pool-size>20</max-pool-size>  
            <prefill>false</prefill>  
            <is-same-rm-override>false</is-same-rm-override>  
          </xa-pool>  
        </connection-definition>  
      </connection-definitions>  
      <admin-objects>  
        <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/activemq/projectName.queue.projectQueue" use-java-context="true" pool-name="PoolName">  
          <config-property name="PhysicalName">  
            ProjectQueue  
          </config-property>  
        </admin-object>  
      </admin-objects>  
    </resource-adapter>  
  </resource-adapters>  
</subsystem>
这是因为您实际上是在将远程jndi名称硬编码到@MessageDriven注释中。我更喜欢使用物理名称,这样远程队列名称就可以更改,而无需更新代码中的注释。当我使用物理名称作为目标值时,我得到以下错误

Failed to connect to broker [ssl://hostname:61617]: User myuser is not authorized to read from: queue://ProjectQueue: javax.jms.JMSSecurityException: User myuser is not authorized to read from: queue://ProjectQueue
  at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:52)
  at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1399)
  at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1428)
  at org.apache.activemq.ActiveMQConnectionConsumer.<init>(ActiveMQConnectionConsumer.java:82)
  at org.apache.activemq.ActiveMQConnection.createConnectionConsumer(ActiveMQConnection.java:1244)
  at org.apache.activemq.ra.ActiveMQEndpointWorker$1.run(ActiveMQEndpointWorker.java:140)
  at org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:223)
  at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)
  at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:808)
  at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)
  at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:828)
  at java.lang.Thread.run(Thread.java:745)
  at org.jboss.threads.JBossThread.run(JBossThread.java:320)
无法连接到代理[ssl://hostname:61617]:用户myuser无权读取:queue://ProjectQueue: javax.jms.JMSSecurityException:用户myuser无权读取:queue://ProjectQueue
位于org.apache.activemq.util.jmsceptionsupport.create(jmsceptionsupport.java:52)
位于org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1399)
位于org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1428)
位于org.apache.activemq.ActiveMQConnectionConsumer。(ActiveMQConnectionConsumer.java:82)
位于org.apache.activemq.ActiveMQConnection.createConnectionConsumer(ActiveMQConnection.java:1244)
位于org.apache.activemq.ra.ActiveMQEndpointWorker$1.run(ActiveMQEndpointWorker.java:140)
位于org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:223)
位于org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)
位于org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:808)
位于org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)
位于org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:828)
运行(Thread.java:745)
位于org.jboss.threads.JBossThread.run(JBossThread.java:320)

是否可以创建一些内部JNDI绑定,以便@MessageDriven注释可以绑定到该名称或管理对象上的某个配置属性?

我找到了解决方案。诀窍是“useJndi”激活ConfigProperty

@MessageDriven(activationConfig = {
  @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/activemq/projectName.queue.projectQueue"),
  @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
  @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
  @ActivationConfigProperty(propertyName = "useJndi", propertyValue = "true")})
public class MyMDB implements MessageListener {
   ...
}
这意味着JNDI查找将在standalone.xml中的资源适配器配置中找到定义的管理对象

<resource-adapters> 
  ...
  <admin-objects>  
    <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/activemq/projectName.queue.projectQueue" use-java-context="true" pool-name="PoolName">  
      <config-property name="PhysicalName">  
        ProjectQueue  
      </config-property>  
    </admin-object>  
  </admin-objects>
</resource-adapters> 

...
项目队列
<resource-adapters> 
  ...
  <admin-objects>  
    <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/activemq/projectName.queue.projectQueue" use-java-context="true" pool-name="PoolName">  
      <config-property name="PhysicalName">  
        ProjectQueue  
      </config-property>  
    </admin-object>  
  </admin-objects>
</resource-adapters>