Java學(xué)習(xí)

          java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經(jīng)搬家了,新的地址是 http://www.javaly.cn 如果有對(duì)文章有任何疑問(wèn)或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂(lè)園)指出,我會(huì)盡力幫助解決。一起進(jìn)步

           

          JMS(Jboss Messaging)的一點(diǎn)使用心得(十三)拔網(wǎng)線后的重連----JMS Connection原理淺析及應(yīng)用(zhuan)

          在前面的文章里,我們介紹了可以自動(dòng)重連的JmsMessageListenerContainer,自動(dòng)重連的原理就是利用了JMS Connction的ExceptionListen機(jī)制?,F(xiàn)在我們討論一下Jms Connection的簡(jiǎn)單原理及應(yīng)用。
              Jboss Messaging管理了兩組Connection,Server端的和Client端的;其實(shí)他們都是一個(gè)東西,因?yàn)檫B接都是相互的嘛。
              Server端的Connection管理是利用 [org.jboss.jms.server.connectionfactory.ConnectionFactory]實(shí)現(xiàn)的,大家可以在[\ jboss-4.2.2.GA\server\messaging1.4SP3\deploy\jboss-messaging.sar\connection -factories-service.xml]里配置它,大家也可以通過(guò)源碼來(lái)研究。不管是Serber端還是Client端都從這個(gè)Factory里 面拿Jms Connection。
              另外,對(duì)Client的Jms Connction還有一個(gè)設(shè)置,就是[org.jboss.remoting.transport.Connector]的設(shè)置,它配置在[\ jboss-4.2.2.GA\server\messaging1.4SP3\deploy\jboss-messaging.sar\remoting -bisocket-service.xml]里。
              根據(jù)Jboss Messaging的默認(rèn)配置,Server端Jms Connection的每隔30秒會(huì)去Check一下所有的JMS 連接,如果發(fā)現(xiàn)連接錯(cuò)誤,則該連接就會(huì)被回收,以提供給其他的Client端使用。這樣做是為了避免出現(xiàn)大量無(wú)用連接而耗費(fèi)系統(tǒng)資源。而Client端的 連接自動(dòng)Check間隔為5分鐘,就是說(shuō)如果直到Client端和Server端的連接斷掉5分鐘后,才會(huì)觸發(fā)Client端Jms Connection的onException。
              這樣就會(huì)出現(xiàn)一種可能,假如Client端和Server端的網(wǎng)線中斷時(shí)間在30秒~5分鐘之間,Server端已經(jīng)回收了該連接,而Client卻認(rèn)為這個(gè)連接仍然OK,那Client端就永遠(yuǎn)收不到Jms消息了...
               我們可以通過(guò)修改設(shè)置來(lái)解決這個(gè)問(wèn)題。首先看看Server端,考慮到Server端的性能和穩(wěn)定性,我們決定不做修改。只有改Client端了。如果我 們讓Client的連接Check時(shí)間小于或者等于30秒,比如說(shuō)29秒,就可以解決這個(gè)問(wèn)題。于是我們可以做以下修改:
          1. connection-factories-service.xml
          <?xml version="1.0" encoding="UTF-8"?>

          <!--
               Messaging Connection Factories deployment descriptor.

               $Id: connection-factories-service.xml 3201 2007-10-19 10:39:50Z timfox $
           
          -->

          <server>

             
          <!-- The default connection factory does not support automatic failover or load balancing-
                  this is so we can maintain compatiblity with applications written for JBoss MQ which use this
                  connection factory.
             
          -->     
             
          <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
                name
          ="jboss.messaging.connectionfactory:service=ConnectionFactory"
                xmbean-dd
          ="xmdesc/ConnectionFactory-xmbean.xml">
                
          <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                
          <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
                
          <depends>jboss.messaging:service=PostOffice</depends>

                
          <attribute name="SupportsFailover">true</attribute>
                
          <!--不需要系統(tǒng)接管RemotingCheck-->
                
          <attribute name="DisableRemotingChecks">true</attribute>
                
                
          <attribute name="JNDIBindings">
                   
          <bindings>
                      
          <binding>/ConnectionFactory</binding>
                      
          <binding>/XAConnectionFactory</binding>
                      
          <binding>java:/ConnectionFactory</binding>
                      
          <binding>java:/XAConnectionFactory</binding>
                   
          </bindings>
                
          </attribute>
             
          </mbean>

             
          <!-- A clustered connection factory that supports automatic failover and load balancing of created
                  connections.
                  This factory is not suitable to be used by MDBs.
             
          -->
             
          <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
                name
          ="jboss.messaging.connectionfactory:service=ClusteredConnectionFactory"
                xmbean-dd
          ="xmdesc/ConnectionFactory-xmbean.xml">
                
          <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                
          <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
                
          <depends>jboss.messaging:service=PostOffice</depends>
                
          <attribute name="DisableRemotingChecks">true</attribute>

                
          <attribute name="JNDIBindings">
                   
          <bindings>
                      
          <binding>/ClusteredConnectionFactory</binding>
                      
          <binding>/ClusteredXAConnectionFactory</binding>
                      
          <binding>java:/ClusteredConnectionFactory</binding>
                      
          <binding>java:/ClusteredXAConnectionFactory</binding>
                   
          </bindings>
                
          </attribute>

                
          <attribute name="SupportsFailover">true</attribute>
                
          <attribute name="SupportsLoadBalancing">true</attribute>      
             
          </mbean>
             
             
          <!-- A connection factory with no JNDI bindings that is used in clustering to create the connections that
                  pull messages from one node to another
             
          -->
             
          <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
                name
          ="jboss.messaging.connectionfactory:service=ClusterPullConnectionFactory"
                xmbean-dd
          ="xmdesc/ConnectionFactory-xmbean.xml">
                
          <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                
          <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
                
          <depends>jboss.messaging:service=PostOffice</depends>
                
          <attribute name="SupportsFailover">false</attribute>
                
          <attribute name="SupportsLoadBalancing">false</attribute>
                
          <attribute name="DisableRemotingChecks">true</attribute>
             
          </mbean>
             
             
          <!-- An example connection factory with all attributes shown 
             
             <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
                name="jboss.messaging.connectionfactory:service=MyExampleConnectionFactory"
                xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
                
                <constructor>
                
                   <!- - You can specify the default Client ID to use for connections created using this factory - -> 
                   
                   <arg type="java.lang.String" value="MyClientID"/>
                   
                </constructor>
                
                <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
                
                <!- - The transport to use - can be bisocket, sslbisocket or http - ->
                
                <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=http</depends>
                
                <depends>jboss.messaging:service=PostOffice</depends>
                
                <!- - PrefetchSize determines the approximate maximum number of messages the client consumer will buffer locally - ->
                
                <attribute name="PrefetchSize">150</attribute>
                
                <!- - Paging params to be used for temporary queues - ->
                
                <attribute name="DefaultTempQueueFullSize">200000</attribute>
                
                <attribute name="DefaultTempQueuePageSizeSize">2000</attribute>
                
                <attribute name="DefaultTempQueueDownCacheSize">2000</attribute>
                
                <!- - The batch size to use when using the DUPS_OK_ACKNOWLEDGE acknowledgement mode - ->
                
                <attribute name="DupsOKBatchSize">5000</attribute>
                
                <!- - Does this connection factory support automatic failover? - ->
                
                <attribute name="SupportsFailover">false</attribute>
                
                <!- - Does this connection factory support automatic client side load balancing? - ->
                
                <attribute name="SupportsLoadBalancing">false</attribute>  
                      
                <!- - The class name of the factory used to create the load balancing policy to use on the client side - ->
                
                <attribute name="LoadBalancingFactory">org.jboss.jms.client.plugin.RoundRobinLoadBalancingFactory</attribute>  

                <!- - Whether we should be strict TCK compliant, i.e. how we deal with foreign messages, defaults to false- ->

                <attribute name="StrictTck">true</attribute>
                
                <!- - Disable JBoss Remoting Connector sanity checks - There is rarely a good reason to set this to true - ->
                
                <attribute name="DisableRemotingChecks">false</attribute>

                <!- - The connection factory will be bound in the following places in JNDI - ->

                <attribute name="JNDIBindings">
                
                   <bindings>
                   
                      <binding>/acme/MyExampleConnectionFactory</binding>
                      
                      <binding>/acme/MyExampleConnectionFactoryDupe</binding>
                      
                      <binding>java:/xyz/CF1</binding>
                      
                      <binding>java:/connectionfactories/acme/connection_factory</binding>
                      
                   </bindings>
                   
                </attribute>   
                 
             </mbean>
             
             
          -->

          </server>

          2. remoting-bisocket-service.xml
          <?xml version="1.0" encoding="UTF-8"?>

          <!--
               Standard bisocket-based Remoting service deployment descriptor.

               $Id: remoting-bisocket-service.xml 3409 2007-12-04 21:32:54Z timfox $
           
          -->

          <server>

             
          <!-- Standard bisocket connector - the bisocket transport only opens connection from client->server
                  so can be used with firewalls where only outgoing connections are allowed.
                  For examples of HTTP and SSL transports see docs/examples 
          -->
             
          <mbean code="org.jboss.remoting.transport.Connector"
                    name
          ="jboss.messaging:service=Connector,transport=bisocket"
                    display-name
          ="Bisocket Transport Connector">
                
          <attribute name="Configuration">
                   
          <config>
                      
          <invoker transport="bisocket">
                      
                         
          <!-- There should be no reason to change these parameters - warning!
                              Changing them may stop JBoss Messaging working correctly 
          -->            
                         
          <attribute name="marshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>
                         
          <attribute name="unmarshaller" isParam="true">org.jboss.jms.wireformat.JMSWireFormat</attribute>
                         
          <attribute name="dataType" isParam="true">jms</attribute>
                         
          <attribute name="socket.check_connection" isParam="true">false</attribute>
                         
          <!--把Timeout時(shí)間修改為29秒,小于30秒-->
                         
          <attribute name="timeout" isParam="true">29000</attribute>
                         
          <attribute name="serverBindAddress">${jboss.bind.address}</attribute>
                         
          <attribute name="serverBindPort">4457</attribute>
                         
          <attribute name="clientSocketClass" isParam="true">org.jboss.jms.client.remoting.ClientSocketWrapper</attribute>
                         
          <attribute name="serverSocketClass">org.jboss.jms.server.remoting.ServerSocketWrapper</attribute>
                         
          <attribute name="numberOfCallRetries" isParam="true">1</attribute>
                         
          <attribute name="pingFrequency" isParam="true">214748364</attribute>
                         
          <attribute name="pingWindowFactor" isParam="true">10</attribute>
                         
          <attribute name="onewayThreadPool">org.jboss.jms.server.remoting.DirectThreadPool</attribute>
                         
          <!-- End immutable parameters -->
                         
                         
          <!-- Periodicity of client pings. Server window by default is twice this figure -->                               
                         
          <attribute name="clientLeasePeriod" isParam="true">10000</attribute>

                         
          <!-- Number of seconds to wait for a connection in the client pool to become free -->
                         
          <attribute name="numberOfRetries" isParam="true">10</attribute>

                         
          <!-- Max Number of connections in client pool. This should be significantly higher than
                              the max number of sessions/consumers you expect 
          -->
                         
          <attribute name="JBM_clientMaxPoolSize" isParam="true">200</attribute>
                         
                         
          <!-- Use these parameters to specify values for binding and connecting control connections to 
                              work with your firewall/NAT configuration
                         <attribute name="secondaryBindPort">xyz</attribute>                           
                         <attribute name="secondaryConnectPort">abc</attribute>               
                         
          -->
                                    
                      
          </invoker>
                      
          <handlers>
                         
          <handler subsystem="JMS">org.jboss.jms.server.remoting.JMSServerInvocationHandler</handler>
                      
          </handlers>
                   
          </config>
                
          </attribute>
             
          </mbean>

          </server>

          問(wèn)題解決。OK! 

          posted on 2008-09-25 17:33 找個(gè)美女做老婆 閱讀(2538) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          公告

          本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
           http://www.javaly.cn

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 邹城市| 鹿邑县| 南皮县| 贡山| 陈巴尔虎旗| 深泽县| 开江县| 上思县| 家居| 安岳县| 顺昌县| 高雄市| 宜城市| 阿坝县| 渭源县| 武邑县| 土默特左旗| 什邡市| 漠河县| 丰镇市| 崇阳县| 茌平县| 鄄城县| 永泰县| 安岳县| 余庆县| 谢通门县| 健康| 新宁县| 霍林郭勒市| 开封市| 手游| 云浮市| 大冶市| 葵青区| 武鸣县| 堆龙德庆县| 五台县| 甘泉县| 鄂托克前旗| 夏邑县|