2014-12-28 76 views
0

可能有人建議我如何使用connectionFactory的-REF

我想使用的connectionFactory-REF騾子配置連接工廠在騾子配置的ConnectionFactory [這是我下面的網址:: :http://www.mulesoft.org/documentation-3.2/display/32X/JMS+Transport+Reference]在騾子配置JMS連接

在上述文檔 - 提到 - 配置的ConnectionFactory

其中最重要的特性之一是connectionFactory的-REF。這是對ConnectionFactory對象的引用,它爲JMS提供者創建新的連接。該對象必須實現接口javax.jms.ConnectionFactory。

連接工廠

所以要實現以下上面是我的騾子configuraion XML

<?xml version="1.0" encoding="UTF-8"?> 

<mule xmlns:smtps="http://www.mulesoft.org/schema/mule/smtps" 
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:https="http://www.mulesoft.org/schema/mule/https" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/smtps http://www.mulesoft.org/schema/mule/smtps/current/mule-smtps.xsd 
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd"> 

<spring:bean name="connectionFactory" class="com.ers.connections.ConnectionFactoryImpl"/> 
<jms:activemq-connector name="Active_MQForApex" connectionFactory-ref="connectionFactory" validateConnections="true" doc:name="Active MQ"/> 
<flow name="apexwritequeueFlow1" doc:name="apexwritequeueFlow1"> 
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="niviTest" doc:name="HTTP"/> 
<logger message="Payload ::: #[payload]" level="INFO" doc:name="Logger"/>    
<jms:outbound-endpoint queue="ANS.RecOps.Incoming" connector-ref="Active_MQForApex" doc:name="JMS"/> 
</flow> 
</mule> 

下面的java類

import javax.jms.Connection; 
import javax.jms.ConnectionFactory; 
import javax.jms.JMSException; 

import org.apache.activemq.ActiveMQConnectionFactory; 

public class ConnectionFactoryImpl implements javax.jms.ConnectionFactory { 

@Override 
public Connection createConnection() throws JMSException {  
// Create a ConnectionFactory 
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("21233", "123", "ssl://xxxx.autonet-yyy.com:443"); 
return connectionFactory.createConnection(); 
} 

@Override 
public Connection createConnection(String arg0, String arg1) 
throws JMSException { 
// TODO Auto-generated method stub 
return null; 
} 

} 



但是我得到這個錯誤

。 Root Exception是:不支持的ConnectionFactory類型:com.ers.connections.ConnectionFactoryImpl。類型:類java.lang.IllegalArgumentException 錯誤2014-12-28 11:53:26,141 [main] org.mule.module.launcher.application.DefaultMuleApplication:null java.lang.IllegalArgumentException:不支持的ConnectionFactory類型:com.ers .connections.ConnectionFactoryImpl

在此先感謝您。 最受讚賞的建議。 謝謝你,至於 NIVI

回答

1

如果你沒有任何真正的好理由,你不要在展後,編寫自己的ConenctionFactory實現你應該使用由JMS提供者提供的一個直接。

所以,你應該用一個bean定義這樣

<spring:bean id="connectionFactory" 
      class="org.apache.activemq.ActiveMQConnectionFactory"> 
    <property name="brokerURL" value="tcp://localhost:61616"/> 
</spring:bean> 
1

您正在使用ActiveMQ的連接器,並期待一個工廠類類型org.apache.activemq.ActiveMQConnectionFactory的。如果你真的需要一個定製的工廠,你ConnectionFactoryImpl類應該擴展該工廠的ActiveMQ:

import org.apache.activemq.ActiveMQConnectionFactory; 

public class ConnectionFactoryImpl extends ActiveMQConnectionFactory { 

    // Override the methods you need 

} 

然後你就可以在連接器的connectionFactory的-REF屬性引用它。

1

你的實現可能不提供任何特殊的功能,如果是這種情況,請只使用默認連接器:

<jms:activemq-connector name="JmsConnector" specification="1.1" /> 

但是,如果你有,你要使用一些特殊的行爲,與ActiveMQ的連接器,您只需要一個實現org.apache.activemq.ActiveMQConnectionFactory的連接工廠,這是因爲these two lines。然後,只需使用類似如下:

<spring:beans> 
     <spring:bean name="myActiveMqConnectionFactory" 
       class="org.apache.activemq.spring.MyActiveMQConnectionFactory" 
       p:brokerURL="vm://esb-amq-broker" <--- Just some example property /> 
    </spring:beans> 

    <jms:activemq-connector name="myJmsConnector" 
          specification="1.1" 
          connectionFactory-ref="AmqConnectionFactory" 
          persistentDelivery="true" /> 

但是請twink兩次對需要這樣的,原來的ActiveMQ連接器可能提供幾乎所有的東西你需要連接高速緩存的exeption。如果這是你需要的,請考慮使用this