JBOSS4中消息bean访问远程服务器的消息队列

在jboss 4中,如果一个appserver A中的消息驱动bean需要访问另外一个appserver B中的消息队列,需要对A及其bean部署文件做相应的配置;对于消息服务器B无需做改动。
对A大致要做3件事情。
1、修改jboss安装目录的jboss-4.0.2\server\default\deploy\jms的jms-ds.xml文件,用红色部分替换掉灰色部分。这里实际上是重新配置了我们如何去访问远程jndi服务器绑定的对象。
<?xml version="1.0" encoding="UTF-8"?>
<connection-factories>
<!-- ==================================================================== -->
<!-- JMS Stuff                                                            -->
<!-- ==================================================================== -->
<!-- The JMS provider loader -->
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
        name="jboss.mq:service=JMSProviderLoader,name=JMSProvider">
    <attribute name="ProviderName">DefaultJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">
      org.jboss.jms.jndi.JNDIProviderAdapter
    </attribute>
    <!-- The combined connection factory -->
    <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>
    <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- Uncomment to use HAJNDI to access JMS
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
       java.naming.provider.url=localhost:1100
    </attribute>
    -->
</mbean>
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
        name="jboss.mq:service=JMSProviderLoader,name=RemoteJMSProvider,server=192.168.0.92">
    <attribute name="ProviderName">QueuehostJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
    <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">XAConnectionFactory</attribute>
    <!-- Connect to JNDI on the host "queuehost" port 1099-->
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jnp.interfaces
        java.naming.provider.url=192.168.0.92:1099
    </attribute>
</mbean>
<!-- The server session pool for Message Driven Beans -->
<mbean code="org.jboss.jms.asf.ServerSessionPoolLoader"
        name="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool">
    <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
    <attribute name="PoolName">StdJMSPool</attribute>
    <attribute name="PoolFactoryClass">
      org.jboss.jms.asf.StdServerSessionPoolFactory
    </attribute>
</mbean>
<!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
<tx-connection-factory>
    <jndi-name>JmsXA</jndi-name>
    <xa-transaction/>
    <rar-name>jms-ra.rar</rar-name>
    <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
    <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
    <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
    <max-pool-size>20</max-pool-size>
    <security-domain-and-application>JmsXARealm</security-domain-and-application>
</tx-connection-factory>
</connection-factories>
2、在消息驱动Bean所在的ejb.jar文件的jboss.xml部署描述符文件中加入如下代码.
<jboss>
   <invoker-proxy-bindings>
     <invoker-proxy-binding>
         <name> lottery-mdb-invoker</name>
         <invoker-mbean>does-not-matter</invoker-mbean>
         <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
         <proxy-factory-config>
              <JMSProviderAdapterJNDI>QueuehostJMSProvider</JMSProviderAdapterJNDI>
            <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
            <MinimumSize>1</MinimumSize>
            <KeepAliveMillis>30000</KeepAliveMillis>
             <MaximumSize>15</MaximumSize>
            <MaxMessages>1</MaxMessages>
            <MDBConfig>
               <ReconnectIntervalSec>10</ReconnectIntervalSec>
               <DLQConfig>
                  <DestinationQueue>queue/DLQ</DestinationQueue>
                   <MaxTimesRedelivered>10</MaxTimesRedelivered>
                  <TimeToLive>0</TimeToLive>
               </DLQConfig>
            </MDBConfig>
         </proxy-factory-config>
      </invoker-proxy-binding>
   </invoker-proxy-bindings>
</jboss>
3、在mdbean配置部分加上如下红色部分语句。
<invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name> 这个名字需要与上边第二步配置的完全匹配。
<jboss>
    
   <enterprise-beans>
     <message-driven>         
      <ejb-name>RecieveMdBean</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/lotappQueue</destination-jndi-name>
           <invoker-bindings>
            <invoker>                     <invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name>
            </invoker>
         </invoker-bindings>
        </message-driven>
   
    </enterprise-beans>
</jboss>
Ok,我们完整的jboss.xml文件内容如下:
<jboss>
   <invoker-proxy-bindings>
      <invoker-proxy-binding>
         <name> lottery-mdb-invoker</name>
         <invoker-mbean>does-not-matter</invoker-mbean>
         <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
         <proxy-factory-config>
              <JMSProviderAdapterJNDI>QueuehostJMSProvider</JMSProviderAdapterJNDI>
            <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
            <MinimumSize>1</MinimumSize>
            <KeepAliveMillis>30000</KeepAliveMillis>
            <MaximumSize>15</MaximumSize>
            <MaxMessages>1</MaxMessages>
            <MDBConfig>
               <ReconnectIntervalSec>10</ReconnectIntervalSec>
               <DLQConfig>
                  <DestinationQueue>queue/DLQ</DestinationQueue>
                  <MaxTimesRedelivered>10</MaxTimesRedelivered>
                  <TimeToLive>0</TimeToLive>
               </DLQConfig>
            </MDBConfig>
         </proxy-factory-config>
      </invoker-proxy-binding>
   </invoker-proxy-bindings>   
   <enterprise-beans>
     <message-driven>         
      <ejb-name>RecieveMdBean</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/lotappQueue</destination-jndi-name>
           <invoker-bindings>
            <invoker>     
               <invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name>
            </invoker>
         </invoker-bindings>
        </message-driven>
   
    </enterprise-beans>
</jboss>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值