锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲情a成黄在线观看,亚洲乱色熟女一区二区三区丝袜,亚洲日本韩国在线http://m.tkk7.com/hk2000c/category/27378.html鎶鏈簮浜庡摬瀛︼紝鍝插鏉ユ簮浜庣敓媧? 鍏沖績鐢熸椿錛屽叧娉ㄥ仴搴鳳紝鍏沖績浠栦漢 zh-cnSat, 17 Nov 2007 19:02:56 GMTSat, 17 Nov 2007 19:02:56 GMT60Mapping a Blob to a byte[]http://m.tkk7.com/hk2000c/archive/2007/11/16/161085.htmlhk2000chk2000cFri, 16 Nov 2007 09:46:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161085.htmlhttp://m.tkk7.com/hk2000c/comments/161085.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161085.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161085.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161085.htmlHibernate 1.2.3 has built-in support for blobs. Hibernate natively maps blob columns to java.sql.Blob. However, it's sometimes useful to read the whole blob into memory and deal with it as a byte array.

One approach for doing this to create a new UserType as follows.

package mypackage;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.sql.Blob;
import cirrus.hibernate.Hibernate;
import cirrus.hibernate.HibernateException;
import cirrus.hibernate.UserType;
public class BinaryBlobType implements UserType
{
public int[] sqlTypes()
{
return new int[] { Types.BLOB };
}
public Class returnedClass()
{
return byte[].class;
}
public boolean equals(Object x, Object y)
{
return (x == y)
|| (x != null
&& y != null
&& java.util.Arrays.equals((byte[]) x, (byte[]) y));
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
Blob blob = rs.getBlob(names[0]);
return blob.getBytes(1, (int) blob.length());
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException
{
st.setBlob(index, Hibernate.createBlob((byte[]) value));
}
public Object deepCopy(Object value)
{
if (value == null) return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}
public boolean isMutable()
{
return true;
}
}

The BinaryBlobType will convert a blob into a byte array and back again.

Here's how to use it. First, define an entity that contains a byte[] property:

public class ImageValue
{
private long id;
private image byte[];
public long getId() { return id; }
public void setId(long id) { this.id = id; }
public byte[] getImage() { return image; }
public void setImage(byte[] image) { this.image = image; }
}

Then map a blob column onto the byte[] property:

<class name="ImageValue" table="IMAGE_VALUE">
<id name="id/>
<property name="image" column="IMAGE" type="mypackage.BinaryBlobType"/>
</class>

Notes:

1) Blobs aren't cachable. By converting the blob into a byte array, you can now cache the entity.

2) This approach reads the whole blob into memory at once.

3) The above type is known to work for reading blobs out of the db. Other usage patterns might also work.

Comments (GK)

I changed isMutable() to return true, since an array is a mutable object.

The use of setBlob() will work on some drivers, but not all. I think its more portable to use setBytes() or even setBinaryStream().

comments (db)

db's comment above was right, setBlob() didn't work on Oracle, I used setBytes().

comments (Chad Woolley)

Below is a modified nullsafeset() that i needed to use to get it to work with tomcat 4.1.27 & oracle 8/9i - the normal calls don't work through the tomcat/dbcp connection pool wrapper objects... (this caused me great pain)

pls note that the setBytes() doesn't seem to work with oracle driver & hibernate

d.birch@eclipsegroup.com.au

public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException
{
if(st instanceof org.apache.commons.dbcp.DelegatingPreparedStatement &&
((org.apache.commons.dbcp.DelegatingPreparedStatement)st).getDelegate()
instanceof oracle.jdbc.OraclePreparedStatement)
{
oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(
((org.apache.commons.dbcp.PoolableConnection)st.getConnection()).getDelegate(), false, oracle.sql.BLOB.DURATION_SESSION);
blob.open(BLOB.MODE_READWRITE);
OutputStream out = blob.getBinaryOutputStream();
try
{
out.write((byte[])value);
out.flush();
out.close();
}
catch(IOException e)
{
throw new SQLException("failed write to blob" + e.getMessage());
}
blob.close();
((oracle.jdbc.OraclePreparedStatement)((org.apache.commons.dbcp.DelegatingPreparedStatement)st).getDelegate()).setBLOB(index, blob);
}
else
{
st.setBlob(index, Hibernate.createBlob((byte[]) value));
}
}
//and.. note the null check, oracle drivers return a null blob...
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
final Blob blob = rs.getBlob(names[0]);
return blob != null?blob.getBytes(1, (int)blob.length()):null;
}

/ comments Vanitha

I had to use the user type to save pdfs as oraBLOBs in oracle 91 database. nullsafeSet

needed a sligh modification , or else ther was a classcastexception. Used oracle Blob instead of Hibernate Blob type and it works.

 public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException
{
oracle.sql.BLOB t_blob = oracle.sql.BLOB.createTemporary(((org.jboss.resource.adapter.jdbc.WrappedConnection) st.getConnection()).getUnderlyingConnection(),
false, oracle.sql.BLOB.DURATION_SESSION);
OutputStream t_out = null;
t_blob.open(BLOB.MODE_READWRITE);
t_out = t_blob.getBinaryOutputStream();
try
{
t_out.write((byte[]) value);
t_out.flush();
t_out.close();
}
catch (IOException e)
{
throw new SQLException("failed write to blob" + e.getMessage());
}
t_blob.close();
st.setBlob(index, t_blob);
}

</code>



hk2000c 2007-11-16 17:46 鍙戣〃璇勮
]]>
spring璋冪敤Oracle瀛樺偍榪囩▼,騫惰繑鍥炵粨鏋滈泦鐨勫畬鏁村疄渚?http://m.tkk7.com/hk2000c/archive/2007/11/16/161082.htmlhk2000chk2000cFri, 16 Nov 2007 09:31:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161082.htmlhttp://m.tkk7.com/hk2000c/comments/161082.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161082.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161082.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161082.html榪欐槸鎬葷粨浠ュ墠浣跨敤spring璋冪敤Oracle瀛樺偍榪囩▼錛屽茍鐢╟ursor榪斿洖緇撴灉闆嗙殑涓涓畬鏁村疄渚嬶紝甯屾湜鑳藉澶у鏈夊府鍔┿?

1. 鍒涘緩琛細

浠g爜
  1. create table TEST_USERS    
  2. (    
  3.   USER_ID  VARCHAR2(10) not null,    
  4.   NAME     VARCHAR2(10) not null,    
  5.   PASSWORD VARCHAR2(20) not null    
  6. )  

 

2. 鍒涘緩瀛樺偍榪囩▼錛?

浠g爜
  1. create or replace package display_users_package is    
  2.      type search_results is ref cursor;    
  3.      procedure display_users_proc(results_out out search_results, userId in test_users.user_id%type);    
  4. end display_users_package;    
  5.   
  6. create or replace package body display_users_package is    
  7.      procedure display_users_proc(results_out out search_results, userId in test_users.user_id%type)    
  8.           is    
  9.           begin    
  10.           if userId is not null then    
  11.               open results_out for select * from test_users where user_id like userId || '%';    
  12.           else    
  13.               open results_out for  select * from test_users;    
  14.           end if;    
  15.       end display_users_proc;    
  16. end display_users_package;  

 

榪欎釜results_out鏄竴涓父鏍囩被鍨嬶紝鐢ㄦ潵榪斿洖鏌ユ壘鐨勭粨鏋滈泦銆?/p>

3.銆瀹屾暣瀹炵幇浠g爜錛?

浠g爜
  1. import java.sql.CallableStatement;   
  2. import java.sql.Connection;   
  3. import java.sql.ResultSet;   
  4. import java.sql.SQLException;   
  5. import java.util.ArrayList;   
  6. import java.util.HashMap;   
  7. import java.util.List;   
  8. import java.util.Map;   
  9.   
  10. import javax.sql.DataSource;   
  11.   
  12. import oracle.jdbc.OracleTypes;   
  13.   
  14. import org.springframework.dao.DataAccessException;   
  15. import org.springframework.jdbc.core.CallableStatementCallback;   
  16. import org.springframework.jdbc.core.CallableStatementCreator;   
  17. import org.springframework.jdbc.core.JdbcTemplate;   
  18.   
  19. import com.spring.stored.procedure.util.DataContextUtil;   
  20.   
  21. /**  
  22.  * @author Jane Jiao  
  23.  *  
  24.  */  
  25. public class SpringStoredProce {   
  26.        
  27.     public List<Map> execute(String storedProc, String params){   
  28.         List<Map> resultList = null;   
  29.         try{   
  30.             final DataSource ds = DataContextUtil.getInstance().getDataSource();   
  31.             final JdbcTemplate template = new JdbcTemplate(ds);   
  32.             resultList = (List<Map>)template.execute(new ProcCallableStatementCreator(storedProc, params),   
  33.                                                      new ProcCallableStatementCallback());   
  34.         }catch(DataAccessException e){   
  35.             throw new RuntimeException("execute method error : DataAccessException " + e.getMessage());   
  36.         }   
  37.          return resultList;   
  38.     }   
  39.        
  40.        
  41.     /**  
  42.      * Create a callable statement in this connection.  
  43.      */  
  44.     private class ProcCallableStatementCreator implements CallableStatementCreator {   
  45.         private String storedProc;   
  46.         private String params;   
  47.            
  48.        
  49.         /**  
  50.          * Constructs a callable statement.  
  51.          * @param storedProc                  The stored procedure's name.  
  52.          * @param params                      Input parameters.  
  53.          * @param outResultCount              count of output result set.  
  54.          */  
  55.         public ProcCallableStatementCreator(String storedProc, String params) {   
  56.             this.params = params;   
  57.             this.storedProc = storedProc;   
  58.         }   
  59.            
  60.         /**  
  61.          * Returns a callable statement  
  62.          * @param conn          Connection to use to create statement  
  63.          * @return cs           A callable statement  
  64.          */  
  65.         public CallableStatement createCallableStatement(Connection conn) {   
  66.             StringBuffer storedProcName = new StringBuffer("call ");   
  67.             storedProcName.append(storedProc + "(");   
  68.             //set output parameters   
  69.             storedProcName.append("?");   
  70.             storedProcName.append(", ");   
  71.                
  72.             //set input parameters   
  73.             storedProcName.append("?");   
  74.             storedProcName.append(")");   
  75.   
  76.             CallableStatement cs = null;   
  77.             try {   
  78.                 // set the first parameter is OracleTyep.CURSOR for oracel stored procedure   
  79.                 cs = conn.prepareCall(storedProcName.toString());   
  80.                 cs.registerOutParameter (1, OracleTypes.CURSOR);   
  81.                // set the sencond paramter   
  82.                 cs.setObject(2, params);   
  83.             } catch (SQLException e) {   
  84.                 throw new RuntimeException("createCallableStatement method Error : SQLException " + e.getMessage());   
  85.             }   
  86.             return cs;   
  87.         }   
  88.            
  89.     }   
  90.        
  91.     /**  
  92.      *   
  93.      * The ProcCallableStatementCallback return a result object,   
  94.      * for example a collection of domain objects.  
  95.      *  
  96.      */  
  97.     private class ProcCallableStatementCallback implements CallableStatementCallback {   
  98.            
  99.         /**  
  100.          * Constructs a ProcCallableStatementCallback.  
  101.          */  
  102.         public ProcCallableStatementCallback() {   
  103.         }   
  104.   
  105.         /**  
  106.          * Returns a List(Map) collection.  
  107.          * @param cs                       object that can create a CallableStatement given a Connection  
  108.          * @return resultsList             a result object returned by the action, or null  
  109.          */  
  110.         public Object doInCallableStatement(CallableStatement cs){   
  111.             List<Map> resultsMap =  new ArrayList<Map>();   
  112.             try {   
  113.                 cs.execute();    
  114.                 ResultSet rs = (ResultSet) cs.getObject(1);   
  115.                 while (rs.next()) {   
  116.                     Map<String, String> rowMap = new HashMap<String, String>();   
  117.                     rowMap.put("userId", rs.getString("USER_ID"));   
  118.                     rowMap.put("name", rs.getString("NAME"));   
  119.                     rowMap.put("password", rs.getString("PASSWORD"));   
  120.                     resultsMap.add(rowMap);   
  121.                 }      
  122.                 rs.close();   
  123.             }catch(SQLException e) {   
  124.                 throw new RuntimeException("doInCallableStatement method error : SQLException " + e.getMessage());   
  125.             }   
  126.             return resultsMap;   
  127.        }   
  128.     }   
  129. }   

 

4.銆嫻嬭瘯浠g爜錛屽湪榪欓噷浣跨敤浜咼unit4嫻嬭瘯錛?

浠g爜
  1. import static org.junit.Assert.assertNotNull;    
  2. import static org.junit.Assert.assertTrue;    
  3.   
  4. import java.util.List;    
  5. import java.util.Map;    
  6.   
  7. import org.junit.After;    
  8. import org.junit.Before;    
  9. import org.junit.Test;    
  10.   
  11. /**   
  12.  * @author Jane Jiao   
  13.  *   
  14.  */    
  15. public class SpringStoredProceTest {    
  16.        
  17.    private SpringStoredProce springStoredProce;    
  18.   
  19.    /**   
  20.     * @throws java.lang.Exception   
  21.     */    
  22.    @Before    
  23.    public void setUp() throws Exception {    
  24.       springStoredProce = new SpringStoredProce();    
  25.    }    
  26.   
  27.    /**   
  28.     * @throws java.lang.Exception   
  29.     */    
  30.    @After    
  31.    public void tearDown() throws Exception {    
  32.       springStoredProce = null;    
  33.    }    
  34.   
  35.    /**   
  36.     * Test method for {@link com.hactl.listingframework.dao.SpringStoredProce#execute(java.lang.String, java.lang.String)}.   
  37.     */    
  38.    @Test    
  39.    public void testExecute() {    
  40.       final String storedProcName = "display_users_package.display_users_proc";    
  41.       final String param = "test";    
  42.       List<Map> resultList = springStoredProce.execute(storedProcName, param);    
  43.       assertNotNull(resultList);    
  44.       assertTrue(resultList.size() > 0);    
  45.       for (int i = 0; i < resultList.size(); i++) {    
  46.          Map rowMap = resultList.get(i);    
  47.          final String userId = rowMap.get("userId").toString();    
  48.          final String name = rowMap.get("name").toString();    
  49.          final String password = rowMap.get("password").toString();    
  50.          System.out.println("USER_ID=" + userId + "\t name=" + name + "\t password=" + password);    
  51.       }    
  52.           
  53.    }    
  54. }  

 

5. 嫻嬭瘯鐨勮緭鍑虹粨鏋滐細

浠g爜
  1. USER_ID=test1    name=aa    password=aa    
  2. USER_ID=test2    name=bb    password=bb    
  3. USER_ID=test3    name=cc    password=cc  


hk2000c 2007-11-16 17:31 鍙戣〃璇勮
]]>
ActiveMQ 瀹炶返涔嬭礬(鍥? ActiveMQ 4.x +JBoss 4.x MDP瀹炴垬綃?http://m.tkk7.com/hk2000c/archive/2007/11/16/161072.htmlhk2000chk2000cFri, 16 Nov 2007 09:10:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161072.htmlhttp://m.tkk7.com/hk2000c/comments/161072.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161072.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161072.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161072.html鍏抽敭瀛?   ActiveMQ    

ActiveMQ 瀹炶返涔嬭礬(鍥? ActiveMQ 4.x +JBoss 4.x MDP瀹炴垬綃?/font>

      鍦?lt;<ActiveMQ 瀹炶返涔嬭礬(涓? ActiveMQ 4.x +JBoss 4.x 鏁村悎綃?/a> >>閲岄潰鎴戜滑姣旇緝璇︾粏鐨勮瑙d簡ActiveMQ涓嶫Boss鐨勬暣鍚?
鏃㈢劧閫夋嫨浜咼Boss,閭d箞欏圭洰閲岄潰鎴栧鎴栧皯閮戒細浣跨敤鍒癊JB,涓嬮潰鎴戜滑灝辮緇嗗湴浠嬬粛濡備綍鍦ˋctiveMQ 4.x+JBOSS 4.x鐜涓嬪紑鍙?br /> Message Driven Bean,騫朵笖涓庝嬌鐢╦bossMQ鍦ㄩ厤緗笂浣滀簡姣旇緝璇︾粏鍦版瘮杈冦傝繖閲岀殑OrderMessage 浠呬粎鏄竴涓嚜鍔ㄧ敓鎴愮殑Message Driven Bean,鍦╫nMessage鏂規硶閲岄潰,浣滄棩蹇楄緭鍏ャ?/p>

 涓. 閰嶇疆ejb-jar.xml
      
        1.  ejb-jar.xml 涓嶈兘浣跨敤XML DTD,闇瑕佷嬌鐢?font color="#ff0000">XML Schema(XSD)
            
寰堝鏈嬪弸鍙兘浣跨敤XDoclet鏉ョ敓鎴恊jb-jar.xml,鎴戣繖閲岀洿鎺ヤ嬌鐢╔Doclet鐢熸垚鐨別jb-jar.xml鏄?/font>

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

           浣嗘槸鍦ˋctiveMQ+JBoss閰嶇疆涓棿闇瑕佷嬌鐢ㄦ柊鐨刋ML Schema鎵嶈兘瀹屾垚瀵箁a鐨勫畾涔?濡備笅.

xml 浠g爜
  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鐨凪essage DriverBean 鍜屼嬌鐢ˋctiveMQ RA閰嶇疆鐨勫尯鍒?/font>

        (1) .浣跨敤JBossMQ鐨凪essageDrivenBean鐨?ejb-jar.xml閰嶇疆

xml 浠g爜
  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閰嶇疆鐨凪essageDrivenBean鐨?font color="#ff0000">ejb-jar.xml閰嶇疆

xml 浠g爜
  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.     <!--浣跨敤浜哸ctivetion-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鏄痳a.xml閲岄潰鎻愪緵鐨勯厤緗睘鎬?(榪欓噷瀹樻柟鐨勬枃妗f槸Destination,DestinationType, 鑰屽疄闄呬笂activemq-ra.rar閲岄潰鐨剅a.xml鏄痙estination,destinationType錛屾敞鎰忓ぇ灝忓啓鍖哄埆)

浜?font face="Arial">. 閰嶇疆jboss.xml
           澶ч儴鍒嗛厤緗兘鏄湪jboss.xml閲岄潰.
         1.浣跨敤JBossMQ 鍜屼嬌鐢ˋctiveMQ RA閰嶇疆Message Driven Bean鐨勫尯鍒?br />            1.) 浣跨敤JBossMQ 鐨勯厤緗?/font>


xml 浠g爜
  1. <message-driven>  
  2.     <ejb-name>OrderMessageejb-name>  
  3.     <destination-jndi-name>queue/testQueuedestination-jndi-name>  
  4. message-driven>  

         2.) 浣跨敤ActiveMQ RA鐨勯厤緗?/p>

xml 浠g爜
  1. <message-driven>  
  2.     <ejb-name>ActiveMQMDPejb-name>  
  3.     <!-- 浣跨敤浜唕esource-adapter-name -->  
  4.     <resource-adapter-name>activemq-ra.rarresource-adapter-name>  
  5.     <!-- 榪欓噷鐨刢onfiguration-name 闇瑕佸拰鍚庨潰container-name 鐨勫悕瀛楃浉鍚?nbsp;-->  
  6.     <configuration-name>ActiveMQ Message Driven Beanconfiguration-name>  
  7. message-driven>  

        2. jboss.xml 閰嶇疆invoker proxy鍜宑ontainer 鏀寔ActiveMQ RA

xml 浠g爜
  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鐨刢ontainer閰嶇疆,榪欓噷鐨?container-name>蹇呴』鍜屼笂闈㈢殑鐩稿悓 鎵嶈兘璧蜂綔鐢?


 

xml 浠g爜
  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 鐨勯厤緗?/font>

涓?鍦⊿ervlet涓氳繃鍙戦佹秷鎭?楠岃瘉涓婇潰鐨凪essage Driven Bean

     涓轟簡楠岃瘉榪欎釜MessageDrivenBean鑳藉姝e父宸ヤ綔,鎴戜嬌鐢ㄤ竴涓緢綆鍗曠殑servlet鍚戣繖涓猶ueue鍙戦佹秷鎭?鍓嶄竴綃囩殑activemq-ds.xml 宸茬粡鎻愪緵鍦ㄥ惎鍔ㄧ殑鏃跺欑粦瀹氫簡JNDI activemq/QueueConnectionFactory,activemq/queue/outbound,鎴戜滑鐩存帴浣跨敤灝辮浜?

java 浠g爜
  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.     }   

鍥?鍏充簬durable鏂瑰紡璁㈤槄topic鐨勮ˉ鍏呰鏄?br />      浣跨敤durable鏂瑰紡,浣犻渶瑕佸湪ejb-jar.xml涓澶栫殑閰嶇疆,subscriptionDurability,clientId,subscriptionName

xml 浠g爜
  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 榪欐牱灝卞彲浠ヤ嬌鐢╠urable鏂瑰紡璁㈤槄topic浜嗐?/p>

鍙傝冩枃妗?
        
JBoss Integration
       ActiveMQ Inbound Communication
銆   ActiveMQ Outbound Communication




hk2000c 2007-11-16 17:10 鍙戣〃璇勮
]]>
ActiveMQ 瀹炶返涔嬭礬(涓? ActiveMQ 4.x +JBoss 4.x 鏁村悎綃?http://m.tkk7.com/hk2000c/archive/2007/11/16/161071.htmlhk2000chk2000cFri, 16 Nov 2007 09:06:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161071.htmlhttp://m.tkk7.com/hk2000c/comments/161071.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161071.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161071.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161071.html鍏抽敭瀛?   ActiveMQ    

      ActiveMQ鏈韓鏄紑婧愰」鐩?鎵浠ラ噰鐢ˋctiveMQ鐨勯」鐩線寰涔熸槸浠ュ叾浠栧紑婧愯蔣浠跺叡鍚屾瀯寤?鐩墠涓繪祦寮婧愬簲鐢ㄦ湇鍔″櫒鏈塀oss,geronimo,JOnAs錛岃屽叾涓璯eronimo 榛樿鐨凧MS Provider灝辨槸ActiveMQ錛岄偅鎴戜滑灝辯潃閲嶄粙緇岮ctiveMQ涓嶫Boss,JOnAs鐨勬暣鍚堟柟妗?/p>

鏈枃鍙傝冧簡 Integrating Apache ActiveMQ with JBoss涓?a >JBoss Integration,鍐嶆牴鎹瑪鑰呭疄闄呮暣鍚堢粡楠屾葷粨鑰屾垚銆?/p>

 涓.鏁村悎闇瑕佺殑鐜.
              jdk1.5
              jboss-4.0.5.GA
              activemq-ra-4.1.0-incubator.rar  (鍦ˋctiveMQ 4.*  lib\optional 鐩綍閲岄潰鏈夊搴旂殑ra鐨勫帇緙╁寘)
銆銆銆寮濮嬫暣鍚堝墠璇風‘淇漥boss鑳藉姝g‘鐨勫惎鍔ㄨ搗鏉ャ?/font>

             浜?鏁村悎姝ラ

              1. 姝ラ涓: 瑙e帇activemq-rar-4.1.0-incubator.rar 鍒?jboss-4.0.5.GA\server\default\deploy\activemq-ra.rar (榪欎釜鏄洰褰曞悕瀛? 涓嬮潰鏄痑ctivemq-rar.rar鐩綍涓嬮潰鐨勬枃浠跺拰瀛愮洰褰?璇鋒敞鎰忕孩鑹叉爣璁扮殑鍦版柟(鍚庨潰浼氶愪竴璇存槑,鏁村悎鐨勮繃紼?

              activeio-core-3.0.0-incubator.jar
              activemq-core-4.1.0-incubator.jar
              activemq-ra-4.1.0-incubator.jar
              backport-util-concurrent-2.1.jar
              commons-logging-1.0.3.jar
              derby-10.1.1.0.jar
              geronimo-j2ee-management_1.0_spec-1.0.jar
              spring-2.0.jar
              spring-1.2.6.jar
              xbean-spring-2.7.jar
              broker-config.xml
              META-INF 
 2.姝ラ浜? 鍒犻櫎澶氫綑鐨?font color="#ff0000">spring-1.2.6.jar,鐢變簬4.1.0鐨剅a閲岄潰鍖呭惈浜?涓笉鍚岀増鏈殑spring浼氳Е鍙戜竴涓猠xception鐨勪駭鐢?https://issues.apache.org/activemq/browse/AMQ-1124, 鑰屼笖涓轟簡浠ュ悗鑳藉浣跨敤鏂扮殑spring schema閰嶇疆鏂瑰紡,鎴戜滑榪欓噷浼氬垹闄?font color="#ff0000">spring-1.2.6.jar
,淇濈暀spring-2.0.jar銆?鏈鏂扮殑snapshot version鐨剅a宸茬粡鍘繪帀浜嗚繖涓浣欑殑spring-1.2.6.jar).

               3.姝ラ涓? 淇敼META-INF\ra.xml,璁㎎Boss浣跨敤broker-config.xml 浣滀負榛樿鐨勯厤緗枃浠墮厤緗産orker. 淇敼涓嬮潰鐨勫湴鏂?br />

  1. <config-property-value>config-property-value>              
  2. <!--  <config-property-value>xbean:broker-config.xml</config-property-value>-->  

 銆銆銆銆 鏀逛負:

  1. <!-- <config-property-value></config-property-value> -->  
  2. <config-property-value>xbean:broker-config.xmlconfig-property-value>  

銆銆銆銆琛ㄧず浣跨敤broker-config.xml鏉ラ厤緗惎鍔ˋctiveMQ.
 
                 4.姝ラ鍥? 淇敼borker-config.xml,榛樿鐨刡orker-config.xml浼氫駭鐢熶竴涓敊璇?鏃犺鏄垜浣跨敤鐨勭増鏈繕鏄渶鍚庣殑snapshot鐗堟湰,榛樿鐨刡orker-config.xml閮戒細璁﹛bean-spring 2.7(snapshot 浣跨敤鐨勬槸2.8)鎶涘嚭exception.瑙e喅鐨勫姙娉曞涓?/div>
       灝?nbsp;       
  1. <beans xmlns="http://activemq.org/config/1.0">  
  2.           <broker useJmx="true" >    
     
     鏀逛負
 
  1. <beans>  
  2. <broker useJmx="true" xmlns="http://activemq.org/config/1.0">  
 
   鍗沖彲
       
              5.姝ラ浜? 灝唜bean-spring-2.7.jar (鎴栬呮槸2.8) 澶嶅埗鍒癹boss-4.0.5.GA\server\default\lib涓嬮潰
 
          涓?浣跨敤鏁村悎瀹屾瘯鐨凙ctiveMQ浣滀負ds緇戝畾鍒癑Boss鐨凧NDI鏈嶅姟銆?/div>
                緙栧啓jboss-4.0.5.GA\server\default\depoly\activemq-ds.xml
xml 浠g爜
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE connection-factories   
  3.     PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"   
  4.     "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">  
  5.   
  6. <connection-factories>  
  7.    <tx-connection-factory>  
  8.       <jndi-name>activemq/QueueConnectionFactory</jndi-name>  
  9.       <xa-transaction/>  
  10.       <track-connection-by-tx/>  
  11.       <rar-name>activemq-ra.rar</rar-name>  
  12.       <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>  
  13.       <ServerUrl>tcp://localhost:61616</ServerUrl>  
  14.       <min-pool-size>1</min-pool-size>  
  15.       <max-pool-size>200</max-pool-size>  
  16.       <blocking-timeout-millis>30000</blocking-timeout-millis>  
  17.       <idle-timeout-minutes>3</idle-timeout-minutes>  
  18.    </tx-connection-factory>  
  19.   
  20.    <tx-connection-factory>  
  21.       <jndi-name>activemq/TopicConnectionFactory</jndi-name>  
  22.       <xa-transaction/>  
  23.       <track-connection-by-tx/>  
  24.       <rar-name>activemq-ra.rar</rar-name>  
  25.       <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>  
  26.       <ServerUrl>tcp://localhost:61616</ServerUrl>  
  27.       <min-pool-size>1</min-pool-size>  
  28.       <max-pool-size>200</max-pool-size>  
  29.       <blocking-timeout-millis>30000</blocking-timeout-millis>  
  30.       <idle-timeout-minutes>3</idle-timeout-minutes>  
  31.    </tx-connection-factory>  
  32.       
  33.    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">  
  34.       <attribute name="JNDIName">activemq/queue/outbound</attribute>  
  35.       <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name=&apos;activemq-ra.rar&apos;</depends>  
  36.       <attribute name="Type">javax.jms.Queue</attribute>  
  37.       <attribute name="Properties">PhysicalName=queue.outbound</attribute>  
  38.    </mbean>  
  39.   
  40.    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">  
  41.       <attribute name="JNDIName">activemq/topic/inbound</attribute>  
  42.       <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name=&apos;activemq-ra.rar&apos;</depends>  
  43.       <attribute name="Type">javax.jms.Topic</attribute>  
  44.       <attribute name="Properties">PhysicalName=topic.inbound</attribute>  
  45.    </mbean>  
  46.   
  47. </connection-factories>  
               
               鍚姩JBoss.濡傛灉鐪嬭浠ヤ笅淇℃伅灝辮〃紺篈ctiveMQ宸茬粡鎴愬姛鍚姩,騫朵笖浣跨敤涓婇潰鐨刣s閰嶇疆鏂囦歡鎴愬姛鍦板皢topic/queue緇戝畾鍒頒簡JNDI鏈嶅姟涓娿?/div>
              ......
              [TransportConnector] Connector tcp://localhost:61616 Started
              [NetworkConnector] Network Connector bridge Started
              [BrokerService] ActiveMQ JMS Message Broker (localhost, ID:MyNoteBook-2165-1173250880171-1:0) started
              ......
              [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/QueueConnectionFactory' to JNDI name 'java:activemq/QueueConnectionFactory'
              [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/TopicConnectionFactory' to JNDI name 'java:activemq/TopicConnectionFactory'
                [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQQueue' at 'activemq/queue/outbound'
                [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQTopic' at 'activemq/topic/inbound
                ......
              
             鍥?楠岃瘉ActiveMQ+JBoss
             榪欓噷浣犲彲浠ヤ嬌鐢ㄧ畝鍗曠殑jms  client榪炴帴鍒癰roker-config.xml閲岄潰鐨勫崗璁繛鎺ュ櫒涓婇潰,榛樿鐨勬槸tcp://localhost:61616
             鍦ㄥ悗闈㈡垜浠細鍦ㄦ鏁村悎鍩虹涓婂紑鍙慚essage Driver Bean鍜屼嬌鐢╯pring MDP 2縐嶆瀯鏋?nbsp;鏉ラ獙璇佹湰嬈ctiveMQ+JBoss鐨勬暣鍚堛?/div>


hk2000c 2007-11-16 17:06 鍙戣〃璇勮
]]>
ActiveMQ 瀹炶返涔嬭礬(浜? 浣跨敤Queue鎴栬匱opic鍙戦?鎺ュ彈娑堟伅 http://m.tkk7.com/hk2000c/archive/2007/11/16/161069.htmlhk2000chk2000cFri, 16 Nov 2007 09:05:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161069.htmlhttp://m.tkk7.com/hk2000c/comments/161069.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161069.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161069.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161069.html

鏈瘒涓昏璁茶В鍦ㄦ湭浣跨敤鍏朵粬妗嗘灦(Spring)鏁村悎鎯呭喌涓?鐙珛鍩轟簬ActiveMQ,浣跨敤JMS瑙勮寖榪涜娑堟伅閫氫俊銆?br />     
     涓.JMS鍥為【
       鍥犱負ActiveMQ鏄竴涓狫MS Provider鐨勫疄鐜?鍥犳鍦ㄥ紑濮嬪疄浣滃墠,鏈夊繀瑕佸涔犱笅JMS鐨勫熀紜鐭ヨ瘑
    Java Message Service (JMS)鏄痵un鎻愬嚭鏉ョ殑涓篔2EE鎻愪緵浼佷笟娑堟伅澶勭悊鐨勪竴濂楄鑼?JMS鐩墠鏈?濂楄鑼冭繕鍦ㄤ嬌鐢↗MS 1.0.2b鍜?.1. 1.1宸茬粡鎴愪負涓繪祦鐨凧MS Provider浜嬪疄涓婄殑鏍囧噯浜?
      *1.1涓昏鍦╯ession涓婇潰鏈変竴浜涢噸瑕佹敼鍙?姣斿鏀寔寤虹珛鍚屼竴session涓婄殑transaction,璁╀粬鏀寔鍚屾椂鍙戦丳2P(Queue)娑堟伅鍜屾帴鍙?br /> Topic娑堟伅銆?br />       
       鍦↗MS涓棿涓昏瀹氫箟浜?縐嶆秷鎭ā寮廝oint-to-Point (鐐瑰鐐?,Publich/Subscribe Model (鍙戝竷/璁㈤槄鑰?錛?br />     鍏朵腑鍦≒ublich/Subscribe 妯″紡涓嬪張鏈塏ondurable subscription鍜宒urable subscription (鎸佷箙鍖栬闃?2縐嶆秷鎭鐞嗘柟寮忋?br />     
     涓嬮潰鏄疛MS瑙勮寖鍩烘湰鐨勬帴鍙e拰瀹炵幇
     JMS Common Interfacse PTP-Specific Interface   Pub/Sub-specific interfaces
     ConnectionFactory     QueueConnectionFactory   TopicConnectionFactory
     Connection            QueueConnection          TopicConnection
     Destination           Queue                    Topic
     Session               QueueSession             TopiSession
     MessageProducer       QueueSender              TopicPublisher
     MessageConsumer       QueueReceiver/QueueBrwer TopicSubscriber


     浜?浣跨敤Queue

         涓嬮潰浠ctiveMQ example鐨勪唬鐮佷負涓昏繘琛岃鏄?br />         
        1. 浣跨敤ActiveMQ鐨凜onnection錛孋onnectionFactory 寤虹珛榪炴帴,娉ㄦ剰榪欓噷娌℃湁鐢ㄥ埌pool
       

java 浠g爜
  1. import org.apache.activemq.ActiveMQConnection   
  2. import org.apache.activemq.ActiveMQConnectionFactory   

        //寤虹珛Connection

java 浠g爜
  1. protected Connection createConnection() throws JMSException, Exception {   
  2.      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);   
  3.      Connection connection = connectionFactory.createConnection();   
  4.      if (durable && clientID!=null) {   
  5.          connection.setClientID(clientID);   
  6.      }   
  7.      connection.start();   
  8.      return connection;   
  9.     }  

        //寤虹珛Session
  

java 浠g爜
  1. protected Session createSession(Connection connection) throws Exception {   
  2.          Session session = connection.createSession(transacted, ackMode);   
  3.          return session;   
  4.         }   

        2銆傚彂閫佹秷鎭殑浠g爜
 //寤虹珛QueueSession
 

java 浠g爜
  1. protected MessageProducer createProducer(Session session) throws JMSException {   
  2.         Destincation destination = session.createQueue("queue.hello");   
  3.         MessageProducer producer = session.createProducer(destination);   
  4.         producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);   
  5.            
  6.         if( timeToLive!=0 )   
  7.             producer.setTimeToLive(timeToLive);   
  8.         return producer;   
  9.         }   

         //浣跨敤Producer鍙戦佹秷鎭埌Queue
    

java 浠g爜
  1. producer.send(message);   

       
        3銆傛帴鍙楁秷鎭?鍦↗MS瑙勮寖閲岄潰,浣犲彲浠ヤ嬌鐢?br />   

java 浠g爜
  1. QueueReceiver/QueueBrowser鐩存帴鎺ュ彈娑堟伅,浣嗘槸鏇村鐨勬儏鍐典笅鎴戜滑閲囩敤娑堟伅閫氱煡鏂瑰紡,鍗沖疄鐜癕essageListener鎺ュ彛   
  2.  public void onMessage(Message message) {   
  3.  //process message   
  4.  }   
  5.           
  6.  //set MessageListner ,receive message   
  7.  Destincation destination = session.createQueue("queue.hello");   
  8.  consumer = session.createConsumer(destination);   
  9.  consumer.setMessageListener(this);   

       
        浠ヤ笂灝辨槸浣跨敤jms queue鍙戦佹帴鍙楁秷鎭殑鍩烘湰鏂瑰紡

 
     涓?Topic

        1. 寤虹珛榪炴帴
   

java 浠g爜
  1. protected Connection createConnection() throws JMSException, Exception {      
  2.         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);      
  3.         Connection connection = connectionFactory.createConnection();      
  4.         //濡傛灉浣犺浣跨敤DurableSubScription 鏂瑰紡,浣犲繀欏諱負connection璁劇疆涓涓狢lientID      
  5.         if (durable && clientID!=null) {      
  6.             connection.setClientID(clientID);      
  7.         }      
  8.         connection.start();      
  9.         return connection;      
  10.        }      

       2. 寤虹珛Session

java 浠g爜
  1. protected Session createSession(Connection connection) throws Exception {      
  2.         Session session = connection.createSession(transacted, ackMode);      
  3.         return session;      
  4.         }    

 3.鍒涘緩Producer 鍙戦佹秷鎭埌Topic   
       

java 浠g爜
  1. //create topic on  session   
  2.        topic = session.createTopic("topic.hello");   
  3.  producer = session.createProducer(topic);   
  4.        //send message    
  5.        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);   
  6.  producer.send(message);   


 4.鍒涘緩Consumer鎺ュ彈娑堟伅(鍩烘湰涓婂拰Queue鐩稿悓)

java 浠g爜
  1. Destincation destination  = session.createTopic("topic.hello");      
  2. MessageConsumer consumer = session.createConsumer(destination);      
  3. consumer.setMessageListener(this);      
  4.            
  5.      //濡傛灉浣犱嬌鐢ㄧ殑鏄疍urable Subscription鏂瑰紡,浣犲繀欏誨湪寤虹珛connection鐨勬椂鍊?nbsp;     
  6.      //璁劇疆ClientID,鑰屼笖寤虹珛comsumer鐨勬椂鍊欎嬌鐢╟reateDurableSubscriber鏂規硶,涓轟粬鎸囧畾涓涓猚onsumerName銆?nbsp;     
  7.  //connection.setClientID(clientId);      
  8.  //consumer = session.createDurableSubscriber((Topic) destination, consumerName);   

       
 鍥?榪炴帴ActiveMQ鐨勬柟寮?br />         ActiveMQConnectionFactory 鎻愪緵浜嗗縐嶈繛鎺ュ埌Broker鐨勬柟寮?a title="ActiveMQ榪炴帴鍗忚" >activemq.apache.org/uri-protocols.html

 甯歌鐨勬湁
 vm://host:port     //vm
 tcp://host:port    //tcp
 ssl://host:port    //SSL
 stomp://host:port  //stomp鍗忚鍙互璺ㄨ璦,鐩墠鏈夊緢澶氱stomp client 搴?java,c#,c/c++,ruby,python...);



hk2000c 2007-11-16 17:05 鍙戣〃璇勮
]]>
ActiveMQ 瀹炶返涔嬭礬(涓) 鍚姩浣犵殑ActiveMQ http://m.tkk7.com/hk2000c/archive/2007/11/16/161070.htmlhk2000chk2000cFri, 16 Nov 2007 09:05:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161070.htmlhttp://m.tkk7.com/hk2000c/comments/161070.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161070.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161070.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161070.html     紼嬪害: 鍏ラ棬


    涓.瀹夎ActiveMQ

       棣栧厛鍘籬ttp://activemq.apache.org/download.html 涓嬭澆鏈鏂扮増鏈?.1.0release (http://activemq.apache.org/activemq-410-release.html),
    瑙e帇apache-activemq-4.1-incubator.zip(鎴栬卆pache-activemq-4.1-incubator.tar.gz)鐩綍濡備笅:
      
       +bin       (windows涓嬮潰鐨刡at鍜寀nix/linux涓嬮潰鐨剆h)
       +conf      (activeMQ閰嶇疆鐩綍,鍖呭惈鏈鍩烘湰鐨刟ctiveMQ閰嶇疆鏂囦歡)
       +data      (榛樿鏄┖鐨?
       +docs      (index,replease鐗堟湰閲岄潰娌℃湁鏂囨。,-.-b涓嶇煡閬撲負鍟ヤ笉甯?
       +example   (鍑犱釜渚嬪瓙
       +lib       (activemMQ浣跨敤鍒扮殑lib)
       -apache-activemq-4.1-incubator.jar  (ActiveMQ鐨刡inary)
       -LICENSE.txt      
       -NOTICE.txt       
       -README.txt
       -user-guide.html


       浣犲彲浠ヤ嬌鐢╞in\activemq.bat(activemq) 鍚姩,濡傛灉涓鍒囬『鍒?浣犲氨浼氱湅瑙佺被浼間笅闈㈢殑淇℃伅
      (緇嗚妭鍙兘涓嶄竴鏍?姣斿璺緞,鎴栬卝mx,jdbc淇℃伅)

  ACTIVEMQ_HOME: D:\java\framework_and_lib\activemq\apache-activemq-4.1-incubator\
bin\..
Loading message broker from: xbean:activemq.xml
INFO  BrokerService                  - ActiveMQ null JMS Message Broker (localho
st) is starting
INFO  BrokerService                  - For help or more information please see:
http://incubator.apache.org/activemq/
INFO  ManagementContext              - JMX consoles can connect to service:jmx:r
mi:///jndi/rmi://localhost:1099/jmxrmi
INFO  JDBCPersistenceAdapter         - Database driver recognized: [apache_derby
_embedded_jdbc_driver]
INFO  DefaultDatabaseLocker          - Attempting to acquire the exclusive lock
to become the Master broker
INFO  DefaultDatabaseLocker          - Becoming the master on dataSource: org.ap
ache.derby.jdbc.EmbeddedDataSource@1d840cd
INFO  JournalPersistenceAdapter      - Journal Recovery Started from: Active Jou
rnal: using 5 x 20.0 Megs at: D:\java\framework_and_lib\activemq\apache-activemq
-4.1-incubator\activemq-data\journal
INFO  JournalPersistenceAdapter      - Journal Recovered: 0 message(s) in transa
ctions recovered.
INFO  TransportServerThreadSupport   - Listening for connections at: tcp://P-SUW
EI:61616
WARN  MulticastDiscoveryAgent        - brokerName not set
INFO  TransportConnector             - Connector default Started
INFO  TransportServerThreadSupport   - Listening for connections at: stomp://P-S
UWEI:61613
INFO  TransportConnector             - Connector stomp Started
INFO  NetworkConnector               - Network Connector default Started
INFO  BrokerService                  - ActiveMQ JMS Message Broker (localhost, I
D:P-SUWEI-1207-1170916242296-1:0) started     

         *銆傚嚑涓皬鎻愮ず
  1. 榪欎釜浠呬粎鏄渶鍩虹鐨凙ctiveMQ鐨勯厤緗?寰堝鍦版柟閮芥病鏈夐厤緗洜姝や笉瑕佺洿鎺ヤ嬌鐢ㄨ繖涓厤緗敤浜庣敓浜х郴緇?br />   2. 鏈夌殑鏃跺欑敱浜庣鍙h鍗犵敤,瀵艱嚧ActiveMQ閿欒,ActiveMQ鍙兘闇瑕佷互涓嬬鍙?099(JMX),61616(榛樿鐨凾ransportConnector)
  3. 濡傛灉娌℃湁鐗╃悊緗戝崱,鎴栬匨S鐨凩oopBackAdpater Multicast浼氭姤涓涓敊璇?/p>

     浜? 嫻嬭瘯浣犵殑ActiveMQ
       
          鐢變簬ActiveMQ鏄竴涓嫭绔嬬殑jms provider,鎵浠ユ垜浠笉闇瑕佸叾浠栦換浣曠涓夋柟鏈嶅姟鍣ㄥ氨鍙互椹笂鍋氭垜浠殑嫻嬭瘯浜?緙栬瘧
     example鐩綍涓嬮潰鐨勭▼搴?br />          
   ProducerTool/ConsumerTool 鏄疛MS鍙傝冮噷闈㈡彁鍒扮殑鍏稿瀷搴旂敤,Producer浜х敓娑堟伅,Consumer娑堣垂娑堟伅
   鑰屼笖榪欎釜渚嬪瓙榪樺彲浠ュ姞鍏ュ弬鏁板府鍔╀綘嫻嬭瘯鍒氭墠鍚姩鐨勬湰鍦癆ctiveMQ鎴栬呮槸榪滅▼鐨凙ctiveMQ

   ProducerTool [url] broker鐨勫湴鍧,榛樿鐨勬槸tcp://localhost:61616
                [true|flase] 鏄惁浣跨敤topic,榛樿鏄痜alse
         [subject] subject鐨勫悕瀛?榛樿鏄疶OOL.DEFAULT
         [durabl] 鏄惁鎸佷箙鍖栨秷鎭?榛樿鏄痜alse
         [messagecount] 鍙戦佹秷鎭暟閲?榛樿鏄?0
         [messagesize] 娑堟伅闀垮害,榛樿鏄?55
         [clientID] durable涓簍rue鐨勬椂鍊?闇瑕侀厤緗甤lientID
         [timeToLive] 娑堟伅瀛樻椿鏃墮棿
         [sleepTime] 鍙戦佹秷鎭腑闂寸殑浼戠湢鏃墮棿
         [transacte]  鏄惁閲囩敤浜嬪姟

         
          ConsumerTool [url] broker鐨勫湴鍧,榛樿鐨勬槸tcp://localhost:61616
                [true|flase] 鏄惁浣跨敤topic,榛樿鏄痜alse
         [subject] subject鐨勫悕瀛?榛樿鏄疶OOL.DEFAULT
         [durabl] 鏄惁鎸佷箙鍖栨秷鎭?榛樿鏄痜alse
         [maxiumMessages] 鎺ュ彈鏈澶ф秷鎭暟閲?0琛ㄧず涓嶉檺鍒?br />        
         [clientID] durable涓簍rue鐨勬椂鍊?闇瑕侀厤緗甤lientID
        
         [transacte]  鏄惁閲囩敤浜嬪姟
         [sleepTime]  鎺ュ彈娑堟伅涓棿鐨勪紤鐪犳椂闂?榛樿鏄?,onMeesage鏂規硶涓嶄紤鐪?br />          [receiveTimeOut] 鎺ュ彈瓚呮椂

          鎴戜滑榪欐牱鍙互浣跨敤:
   java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ProducerTool  tcp://192.168.3.142:61616 test.mysubject
   java -classpath .\apache-activemq-4.1-incubator.jar;example\bin ConsumerTool  tcp://192.168.3.142:61616 test.mysubject

   褰撶劧浣犲彲浠ヤ嬌鐢ㄤ笂闈㈢殑鍙傛暟榪涜鏇村鏉傜殑嫻嬭瘯,鎸佷箙,浜嬪姟

   濡傛灉鍑虹幇涓嬮潰鐨勪俊鎭?鎭枩浣?浣犵殑ActiveMQ宸茬粡鑳藉宸ヤ綔浜?br />         
  Connecting to URL: tcp://192.168.3.142:61616
  Publishing a Message with size 255 to queue: TOOL.DEFAULT
  Using non-durable publishing
  Sleeping between publish 0 ms
  Sending message: Message: 0 sent at: Thu Feb 08 15:05:34 CST 2007  ...
  Sending message: Message: 1 sent at: Thu Feb 08 15:05:34 CST 2007  ...
         銆傘傘傘傘傘傘傘?/p>


  Connecting to URL: tcp://192.168.3.142:61616
  Consuming queue: test.mysubject
         Using non-durable subscription
         Received: Message: 0 sent at: Thu Feb 08 14:51:34 CST 2007  ...
         Received: Message: 1 sent at: Thu Feb 08 14:51:34 CST 2007  ...
  銆傘傘傘?/p>


         涓?灝忕粨
     
      鎴戜滑宸茬粡涓嬭澆,鍚姩,騫朵笖鐢ㄧ▼搴忔祴璇曚簡鎴戜滑鐨凙ctiveMQ,鑰屽悗闈㈠皢鍦ㄨ繖涓兘璺戝緱ActiveMQ榪涗竴姝ョ殑璧頒笅鍘?涓姝ヤ竴姝ュ睍紺篈ctiveMQ鐨勯珮綰х壒鎬с?/p>


hk2000c 2007-11-16 17:05 鍙戣〃璇勮
]]>
鍦⊿pring涓厤緗甁MShttp://m.tkk7.com/hk2000c/archive/2007/11/16/161064.htmlhk2000chk2000cFri, 16 Nov 2007 08:49:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161064.htmlhttp://m.tkk7.com/hk2000c/comments/161064.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161064.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161064.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161064.html閮侀椃浜嗕笁澶╋紝浠婂ぉ緇堜簬鎶奐MS寮勫嚭鏉ヤ簡錛屽氨鏄彂閫佹秷鎭紝鐒跺悗娑堟伅鐩戝惉鍣ㄦ帴鏀跺埌浜嗘秷鎭悗鍙戦侀偖浠剁粰綆$悊鍛?/p>

鍏堢湅web.xml閲岄潰鍏充簬activemq鐨刬nvoke

<!--璋冪敤activemq -->
    <context-param >
     <param-name>brokerURI </param-name >
     <param-value>/WEB-INF/activemq.xml </param-value >
    </context-param>
   
    <listener>
       <listener-class>org.activemq.web.SpringBrokerContextListener</listener-class>
    </listener>


閮侀椃浜嗕笁澶╋紝浠婂ぉ緇堜簬鎶奐MS寮勫嚭鏉ヤ簡錛屽氨鏄彂閫佹秷鎭紝鐒跺悗娑堟伅鐩戝惉鍣ㄦ帴鏀跺埌浜嗘秷鎭悗鍙戦侀偖浠剁粰綆$悊鍛?/p>

鍏堢湅web.xml閲岄潰鍏充簬activemq鐨刬nvoke

<!--璋冪敤activemq -->
    <context-param >
     <param-name>brokerURI </param-name >
     <param-value>/WEB-INF/activemq.xml </param-value >
    </context-param>
   
    <listener>
       <listener-class>org.activemq.web.SpringBrokerContextListener</listener-class>
    </listener>

鐒跺悗鏄湪涓婁笅鏂囦腑瀹氫箟鐨凧msTemplate鍜宎ctivemq鐩戝惉

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!--JMS Template-->
    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory">
      <bean class="org.activemq.ActiveMQConnectionFactory">
       <property name="brokerURL">
        <value>tcp://localhost:61616</value>
       </property>
      </bean>
     </property>
     
      <property name="defaultDestinationName" value="Hello.Queue"/>
    </bean>

   <bean id="activeMQContainer" class="org.activemq.jca.JCAContainer">
     <property name="workManager">
       <bean id="workManager" class="org.activemq.work.SpringWorkManager"/>
     </property>

     <property name="resourceAdapter">
       <bean id="activeMQResourceAdapter"
           class="org.activemq.ra.ActiveMQResourceAdapter">
         <property name="serverUrl" value="tcp://localhost:61616"/>
       </bean>
     </property>
   </bean>
 

  <!--鐩戝惉 Message 鐨凪essage Driven POJO-->
    <bean id="HelloPlaceBean" class="com.officetao.jms.HelloMDP" autowire="byName"/>

  <bean id="HelloMDP" factory-method="addConnector" factory-bean="activeMQContainer">
     <property name="activationSpec">
       <bean class="org.activemq.ra.ActiveMQActivationSpec">
         <property name="destination" value="Hello.Queue"/>
         <property name="destinationType" value="javax.jms.Queue"/>
       </bean>
     </property>
     <property name="ref" value="HelloBean" />
   </bean>

</beans>

寤虹珛涓涓ā鎷熺殑鍙戦佹秷鎭殑bean錛屽唴瀹瑰涓?/font>

final String mailContent = "鏂板鍗曞彿涓?000鐨勮鍗? 閲戦";
  try {
            if (jmsTemplate != null)
                jmsTemplate.send(new MessageCreator() {
                    public Message createMessage(Session session)
                            throws JMSException {
                        Message message = session.createMessage();
                        message.setStringProperty("content", mailContent);
                        return message;
                    }
                });
        }
        catch (Exception e) {
            logger.error("JMS error when place order:", e);
        }

鏈鍚庡氨鏄洃鍚秷鎭劧鍚庨噰鍙栬鍔ㄧ殑bean


public class HelloMDP implements MessageListener {


 
 public void onMessage(javax.jms.Message arg0) {
  
  try   {  
            subAuthenticator   subauth   =   new   subAuthenticator("閭鐧婚檰鍚?,"瀵嗙爜");//smtp楠岃瘉   authenticator  
            props.put("mail.smtp.host","smtp.163.com");  
            props.put("mail.smtp.auth","true");  
            session   =   Session.getInstance(props,subauth);  
            MimeMessage   message   =   new   MimeMessage(session);  
            message.setRecipient(Message.RecipientType.TO,new   InternetAddress("
鎺ユ敹閭歡鐨勯偖綆?/font>"));  
            message.setFrom(new   InternetAddress("
鑷繁鐨勯偖綆?/font>"));  
            message.setSubject("ok");  
            message.setText("if you see it,it works!");  
            Transport.send(message);
        }  
        catch(AuthenticationFailedException   e1){  
            System.out.println("SMTP璁よ瘉鍑洪敊錛?);  
        }  
        catch   (MessagingException   e)   {  
            e.printStackTrace();
        }  
 
}

public   static   Properties   props   =   System.getProperties();
public   static   Session   session   =   null;  

/**  
*姝ゅ唴閮ㄧ被瀹氫箟浜唖mtp璁よ瘉鏂規硶  
*/  
public   class   subAuthenticator   extends   Authenticator{  
private   String   userName;  
private   String   password;  
public   subAuthenticator(String   user,String   pass){  
    userName=user;  
    password=pass;  
}  
public   PasswordAuthentication   getPasswordAuthentication(){  
    return   new   PasswordAuthentication(userName,password);  
}  



hk2000c 2007-11-16 16:49 鍙戣〃璇勮
]]>
tomcat涓嬪簲鐢↗MS http://m.tkk7.com/hk2000c/archive/2007/11/16/161062.htmlhk2000chk2000cFri, 16 Nov 2007 08:48:00 GMThttp://m.tkk7.com/hk2000c/archive/2007/11/16/161062.htmlhttp://m.tkk7.com/hk2000c/comments/161062.htmlhttp://m.tkk7.com/hk2000c/archive/2007/11/16/161062.html#Feedback0http://m.tkk7.com/hk2000c/comments/commentRss/161062.htmlhttp://m.tkk7.com/hk2000c/services/trackbacks/161062.html JMS鍋氫負J2EE鐨勯珮綰ч儴鍒嗕竴鐩磋挋鐫涓灞傜縐樼殑闈㈢罕錛屼綔涓篔MS鐨勫畾鍒惰匰UN鍙瀹氫簡JMS瑙勮寖錛岃薄寰堝鍏朵粬SUN浜у搧涓鏍瘋澶氬鍘傚晢鎻愪緵浜嗗叿浣撶殑瀹炵幇銆備絾鏄綔涓簍omcat鍜孯ESIN錛堜粖騫村垵瀹e竷鍏ㄩ儴鏀寔J2EE瑙勮寖錛夈傝繖浜涢潰鍚戜綆绔絾鍗磋騫挎硾搴旂敤鐨勬湇鍔″櫒鏈韓騫朵笉瀵笿MS鎻愪緵鏀寔銆傚簡騫哥殑鏄痮penjms鍜宎ctiveMQ涓ゅ寮婧愯蔣浠舵彁渚涗簡鎻掍歡寮忕殑鏀寔銆?

    鍦ㄥ簲鐢ㄤ簡涓浜涘紑鍙戞鏋跺spring鐨勯」鐩噷濡傛灉瑕佷嬌鐢ㄥ埌JMS錛岃櫧鐒禨PRING鎻愪緵浜嗛儴鍒嗗JMS鐨勬敮鎸佷絾緇忚繃鎴戜竴孌墊椂闂寸殑搴旂敤鍙戠幇錛孫O鐨勫皝瑁呭湪鏌愪簺鍦版柟鍙嶈屾垚涓哄紑鍙戣繃紼嬩腑鐨勯殰紕嶃傚湪瀹炵幇璇稿鐩戝惉涔嬬被鐨勪唬鐮佹閲屼嬌浜洪潪甯哥殑鎳婃伡錛屽嵆浣跨敤callback(鍥炶皟)鏈変簺涓滆タ浠嶇劧涓嶈兘澶熷緢濂界殑琚彇鍒般?

涓嬮潰灝變竴浜汿OMCAT涓婇潰JMS鐨勬敮鎸佹棦瀹炵幇鍋氫竴涓嬫暣鐞嗐?

1.寰堣嚜鐒剁殑浣犻渶瑕佷笅杞絁MS瀹炵幇,濡?opnerJMS鎴栬卆ctiveMQ .涓嬭澆鍦板潃www.jmsopen.com 鎴杦ww.activeMQ.com

2.鏈嶅姟鍣ㄤ笅杞戒互鍚庣殑鍏蜂綋閰嶇疆鍦ㄤ互涓婁袱涓綉绔欎笂閮芥湁寰堣緇嗙殑璇存槑錛屽氨涓嶅啀鍒椾婦浜嗐?

3.鍜學EB鏈嶅姟鍣ㄧ殑鏁村悎錛岄鍏堣閰嶇疆搴旂敤鐨剋eb.xml榪欎釜鏂囦歡閰嶇疆濡備笅錛?

1  <context-param>
            2  <param-name>brokerURI</param-name>
            3  <param-value>/WEB-INF/activemq.xml</param-value>
            4  </context-param>
            5
            6  <listener>
            7  <listener-class>org.activemq.web.SpringBrokerContextListener</listener-class>
            8  </listener>


灝嗚繖涓孌典唬鐮佹斁鍒皐eb.xml閲屻傛敞鎰忓埌activemq.xml鏂囦歡錛屾槸jms鏈嶅姟鍣ㄧ殑鍏蜂綋閰嶇疆錛?

<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE beans PUBLIC
            "-//ACTIVEMQ//DTD//EN"
            "http://activemq.org/dtd/activemq.dtd">
            <beans>
            <!-- ===================== -->
            <!-- ActiveMQ Broker Configuration -->
            <!-- ===================== -->
            <broker>
            <connector>
            <tcpServerTransport
            uri="tcp://localhost:61616"
            useAsyncSend="true"
            maxOutstandingMessages="50"/>
            </connector>
            <!-- to enable Stomp support uncomment this
            <connector>
            <serverTransport
            uri="stomp://localhost:61626"/>
            </connector>
            -->
            <persistence>
            <jdbcPersistence
            dataSourceRef="oracle-ds"/>
            </persistence>
            </broker>
            <!-- ======================= -->
            <!-- JDBC DataSource Configurations -->
            <!-- ======================= -->
            <!-- The Derby Datasource
            that will be used by the Broker -->
            <bean id="derby-ds" class=
            "org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <property name="driverClassName">
            <value>
            org.apache.derby.jdbc.EmbeddedDriver
            </value>
            </property>
            <property name="url">
            <!-- Use a URL like
            'jdbc:hsqldb:hsql://localhost:9001'
            if you want to connect to a remote hsqldb -->
            <value>
            jdbc:derby:derbydb;create=true
            </value>
            </property>
            <property name="username">
            <value></value>
            </property>
            <property name="password">
            <value></value>
            </property>
            <property name="poolPreparedStatements">
            <value>true</value>
            </property>
            </bean>
            </beans>


姝ゆ椂錛屽湪鍚姩浣犵殑TOMCAT鐨勬椂鍊欎細鐪嬪埌JMS鏈嶅姟鍣ㄥ凡緇忕粦鍒頒簡涓婇潰銆?/a>

hk2000c 2007-11-16 16:48 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 又大又硬又爽免费视频| 亚洲片一区二区三区| 天天影视色香欲综合免费| 亚洲国产夜色在线观看| 国产做床爱无遮挡免费视频| 免费中文熟妇在线影片 | 国产精品免费综合一区视频| 成人黄软件网18免费下载成人黄18免费视频| 在免费jizzjizz在线播| 人成电影网在线观看免费| 免费看黄福利app导航看一下黄色录像 | 在线观看黄片免费入口不卡| 一区二区亚洲精品精华液| 亚洲最大福利视频| 亚洲av永久无码精品国产精品| 亚洲AV无码成人网站久久精品大| 国产亚洲精品国产| 免费人成在线观看视频播放| 亚洲А∨精品天堂在线| 亚洲人JIZZ日本人| 亚洲一区二区三区首页| 亚洲伊人色一综合网| 亚洲成a人无码亚洲成www牛牛| 亚洲精品在线免费观看视频| 亚洲国产精品无码成人片久久 | 久久久久久久久久国产精品免费| 99精品在线免费观看| 国产精品免费久久久久久久久| 秋霞人成在线观看免费视频| 亚洲网站免费观看| 日韩高清在线免费观看| 亚洲日本韩国在线| 国产男女猛烈无遮挡免费视频网站| 亚洲AV无码一区二区三区在线观看| 久久夜色精品国产亚洲| 亚洲成AV人综合在线观看| 夜夜亚洲天天久久| 亚洲国产成人久久精品软件| 国产视频精品免费视频| 91香蕉国产线在线观看免费| 中文字幕免费不卡二区|