<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    hk2000c技術(shù)專欄

    技術(shù)源于哲學(xué),哲學(xué)來源于生活 關(guān)心生活,關(guān)注健康,關(guān)心他人

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      111 隨筆 :: 1 文章 :: 28 評(píng)論 :: 0 Trackbacks
    關(guān)鍵字:   ActiveMQ    

    ActiveMQ 實(shí)踐之路(四) ActiveMQ 4.x +JBoss 4.x MDP實(shí)戰(zhàn)篇

          在<<ActiveMQ 實(shí)踐之路(三) ActiveMQ 4.x +JBoss 4.x 整合篇 >>里面我們比較詳細(xì)的講解了ActiveMQ與JBoss的整合,
    既然選擇了JBoss,那么項(xiàng)目里面或多或少都會(huì)使用到EJB,下面我們就詳細(xì)地介紹如何在ActiveMQ 4.x+JBOSS 4.x環(huán)境下開發(fā)
    Message Driven Bean,并且與使用jbossMQ在配置上作了比較詳細(xì)地比較。這里的OrderMessage 僅僅是一個(gè)自動(dòng)生成的Message Driven Bean,在onMessage方法里面,作日志輸入。

     一. 配置ejb-jar.xml
          
            1.  ejb-jar.xml 不能使用XML DTD,需要使用XML Schema(XSD)
                
    很多朋友可能使用XDoclet來生成ejb-jar.xml,我這里直接使用XDoclet生成的ejb-jar.xml是

    <!--CTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dt-->

               但是在ActiveMQ+JBoss配置中間需要使用新的XML Schema才能完成對(duì)ra的定義,如下.

    xml 代碼
    1. <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">  

     

    2. ejb-jar.xml 直接使用JBossMQ的Message DriverBean 和使用ActiveMQ RA配置的區(qū)別

            (1) .使用JBossMQ的MessageDrivenBean的 ejb-jar.xml配置

    xml 代碼
    1. <!-- Message Driven Beans -->  
    2. <message-driven>  
    3.     <description>  
    4.           
    5.     description>  
    6.     <display-name>Name for OrderMessagedisplay-name>  
    7.     <ejb-name>OrderMessageejb-name>  
    8.     <ejb-class>com.mostone.ejb.OrderMessageejb-class>  
    9.     <transaction-type>Containertransaction-type>  
    10.     <acknowledge-mode>Auto-acknowledgeacknowledge-mode>  
    11.     <message-driven-destination>  
    12.         <destination-type>javax.jms.Queuedestination-type>  
    13.     message-driven-destination>  
    14. message-driven>  

         (2). 使用ActiveMQ RA配置的MessageDrivenBean的ejb-jar.xml配置

    xml 代碼
    1. <!-- Message Driven Beans -->  
    2. <message-driven>  
    3.     <description>  
    4.           
    5.     description>  
    6.     <display-name>Name for OrderMessagedisplay-name>  
    7.     <ejb-name>OrderMessageejb-name>  
    8.     <ejb-class>com.mostone.ejb.OrderMessageejb-class>  
    9.     <transaction-type>Containertransaction-type>  
    10.     <acknowledge-mode>Auto-acknowledgeacknowledge-mode>  
    11.     <!--使用了activetion-config-->  
    12.     <activation-config>  
    13.         <activation-config-property>  
    14.             <activation-config-property-name>destinationactivation-config-property-name>  
    15.             <activation-config-property-value>queue.outboundactivation-config-property-value>  
    16.         activation-config-property>  
    17.         <activation-config-property>  
    18.             <activation-config-property-name>destinationTypeactivation-config-property-name>  
    19.             <activation-config-property-value>javax.jms.Queueactivation-config-property-value>  
    20.         activation-config-property>  
    21.     activation-config>  
    22. message-driven>  

            其中destination,destinationType是ra.xml里面提供的配置屬性,(這里官方的文檔是Destination,DestinationType, 而實(shí)際上activemq-ra.rar里面的ra.xml是destination,destinationType,注意大小寫區(qū)別)

    . 配置jboss.xml
               大部分配置都是在jboss.xml里面.
             1.使用JBossMQ 和使用ActiveMQ RA配置Message Driven Bean的區(qū)別
               1.) 使用JBossMQ 的配置


    xml 代碼
    1. <message-driven>  
    2.     <ejb-name>OrderMessageejb-name>  
    3.     <destination-jndi-name>queue/testQueuedestination-jndi-name>  
    4. message-driven>  

             2.) 使用ActiveMQ RA的配置

    xml 代碼
    1. <message-driven>  
    2.     <ejb-name>ActiveMQMDPejb-name>  
    3.     <!-- 使用了resource-adapter-name -->  
    4.     <resource-adapter-name>activemq-ra.rarresource-adapter-name>  
    5.     <!-- 這里的configuration-name 需要和后面container-name 的名字相同 -->  
    6.     <configuration-name>ActiveMQ Message Driven Beanconfiguration-name>  
    7. message-driven>  

            2. jboss.xml 配置invoker proxy和container 支持ActiveMQ RA

    xml 代碼
    1. <invoker-proxy-bindings>  
    2.     <invoker-proxy-binding>  
    3.         <name>activemq-message-driven-beanname>  
    4.         <invoker-mbean>defaultinvoker-mbean>  
    5.         <proxy-factory>org.jboss.ejb.plugins.inflow.JBossMessageEndpointFactoryproxy-factory>  
    6.         <proxy-factory-config>  
    7.             <endpoint-interceptors>  
    8.                 <interceptor>org.jboss.proxy.ClientMethodInterceptorinterceptor>  
    9.                 <interceptor>org.jboss.ejb.plugins.inflow.MessageEndpointInterceptorinterceptor>  
    10.                 <interceptor>org.jboss.proxy.TransactionInterceptorinterceptor>  
    11.                 <interceptor>org.jboss.invocation.InvokerInterceptorinterceptor>  
    12.             endpoint-interceptors>  
    13.         proxy-factory-config>  
    14.     invoker-proxy-binding>  
    15. invoker-proxy-bindings>  

    MessageDrivenBean的container配置,這里的必須和上面的相同 才能起作用.


     

    xml 代碼
    1. <container-configurations>  
    2.     <container-configuration>  
    3.         <container-name>ActiveMQ Message Driven Beancontainer-name>  
    4.         <call-logging>falsecall-logging>  
    5.         <invoker-proxy-binding-name>activemq-message-driven-beaninvoker-proxy-binding-name>  
    6.         <container-interceptors>  
    7.             <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptorinterceptor>  
    8.                 <interceptor>org.jboss.ejb.plugins.LogInterceptorinterceptor>  
    9.                 <interceptor>org.jboss.ejb.plugins.RunAsSecurityInterceptorinterceptor>  
    10.                 <!-- CMT -->  
    11.                 <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMTinterceptor>  
    12.                 <interceptor transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>  
    13.                 <interceptor transaction="Container" metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptorinterceptor>  
    14.                 <interceptor transaction="Container">org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>  
    15.                 <!-- BMT -->  
    16.                 <interceptor transaction="Bean">org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>  
    17.                 <interceptor transaction="Bean">org.jboss.ejb.plugins.MessageDrivenTxInterceptorBMTinterceptor>  
    18.                 <interceptor transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>  
    19.                 <interceptor transaction="Bean" metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptorinterceptor>  
    20.                 <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptorinterceptor>  
    21.         container-interceptors>  
    22.         <instance-pool>org.jboss.ejb.plugins.MessageDrivenInstancePoolinstance-pool>  
    23.         <instance-cache>instance-cache>  
    24.         <persistence-manager>persistence-manager>  
    25.         <container-pool-conf>  
    26.                 <MaximumSize>100MaximumSize>  
    27.         container-pool-conf>  
    28.         container-configuration>  
    29. container-configurations>  

    以上就是ActiveMQ+JBoss InBound 的配置

    三.在Servlet中通過發(fā)送消息,驗(yàn)證上面的Message Driven Bean

         為了驗(yàn)證這個(gè)MessageDrivenBean能夠正常工作,我使用一個(gè)很簡單的servlet向這個(gè)queue發(fā)送消息,前一篇的activemq-ds.xml 已經(jīng)提供在啟動(dòng)的時(shí)候綁定了JNDI activemq/QueueConnectionFactory,activemq/queue/outbound,我們直接使用就行了,

    java 代碼
    1. try {   
    2.         initialContext = new InitialContext();   
    3.         QueueConnectionFactory connectionFactory = (QueueConnectionFactory) initialContext   
    4.                 .lookup("java:activemq/QueueConnectionFactory");   
    5.            Connection con=connectionFactory.createConnection();   
    6.         Session session =  con.createSession(false, Session.AUTO_ACKNOWLEDGE);   
    7.   
    8.         Queue queue = (Queue) initialContext.lookup("activemq/queue/outbound");   
    9.         MessageProducer producer = session.createProducer(queue);   
    10.         TextMessage txtMessage = session.createTextMessage();   
    11.         txtMessage.setText("A");   
    12.         producer.send(txtMessage);   
    13.         producer.close();   
    14.         session.close();   
    15.         con.close();   
    16.            
    17.     } catch (NamingException e) {   
    18.         // TODO Auto-generated catch block   
    19.         e.printStackTrace();   
    20.     } catch (JMSException e) {   
    21.         // TODO Auto-generated catch block   
    22.         e.printStackTrace();   
    23.     }   

    四.關(guān)于durable方式訂閱topic的補(bǔ)充說明
         使用durable方式,你需要在ejb-jar.xml中額外的配置,subscriptionDurability,clientId,subscriptionName

    xml 代碼
    1. <activation-config>  
    2.     <activation-config-property>  
    3.         ......   
    4.         <activation-config-property>  
    5.             <activation-config-property-name>subscriptionDurabilityactivation-config-property-name>  
    6.             <activation-config-property-value>Durableactivation-config-property-value>  
    7.         activation-config-property>  
    8.         <activation-config-property>  
    9.             <activation-config-property-name>clientIdactivation-config-property-name>  
    10.             <activation-config-property-value>fooactivation-config-property-value>  
    11.         activation-config-property>  
    12.         <activation-config-property>  
    13.             <activation-config-property-name>subscriptionNameactivation-config-property-name>  
    14.             <activation-config-property-value>baractivation-config-property-value>  
    15.         activation-config-property>  
    16.         ......   
    17.     activation-config-property>  
    18. activation-config>  

     

    ok 這樣就可以使用durable方式訂閱topic了。

    參考文檔:
            JBoss Integration
           ActiveMQ Inbound Communication
        ActiveMQ Outbound Communication


    posted on 2007-11-16 17:10 hk2000c 閱讀(573) 評(píng)論(0)  編輯  收藏 所屬分類: JMS
    主站蜘蛛池模板: 国产大片线上免费看| 国偷自产一区二区免费视频| 成人女人A级毛片免费软件| 亚洲高清在线观看| AAAAA级少妇高潮大片免费看 | 在线观看特色大片免费视频 | 亚洲国产免费综合| 黄网站在线播放视频免费观看 | 久久精品国产大片免费观看 | 亚洲女人影院想要爱| 波多野结衣免费在线观看| tom影院亚洲国产一区二区| 一个人免费高清在线观看| 亚洲精品无码人妻无码| 免费看的黄色大片| 免费无码一区二区| 亚洲av综合avav中文| 国产高清不卡免费在线| 亚洲第一第二第三第四第五第六| 免费少妇a级毛片| 三年片免费观看大全国语| 亚洲AV日韩AV天堂一区二区三区| 久热中文字幕在线精品免费| 亚洲av日韩av永久在线观看| 亚洲无线一二三四区手机| a毛片免费观看完整| 亚洲乱码无限2021芒果| 国产一级淫片视频免费看| 国产成人无码区免费内射一片色欲 | 国产高清在线免费视频| 四虎精品成人免费视频| 亚洲AV无码专区在线播放中文| 在线永久免费的视频草莓| 亚洲sm另类一区二区三区| 综合亚洲伊人午夜网 | 黄网站在线播放视频免费观看| 亚洲va无码va在线va天堂| 精品久久久久成人码免费动漫| 一级女性全黄久久生活片免费| 亚洲伦理一区二区| 免费一看一级毛片人|