【问题标题】:Configuring JMS connectionfactory in mule在 mule 中配置 JMS connectionfactory
【发布时间】:2015-02-24 23:21:11
【问题描述】:

谁能建议我如何使用 connectionFactory-ref 在 mule 中配置 connectionfactory

我正在尝试使用connectionFactory-ref在mule中配置connectionfactory [这是我关注的url :::http://www.mulesoft.org/documentation-3.2/display/32X/JMS+Transport+Reference]。

在上述文档中 - 提到 - 配置 ConnectionFactory

最重要的属性之一是connectionFactory-ref。这是对 ConnectionFactory 对象的引用,该对象为您的 JMS 提供者创建新连接。该对象必须实现接口 javax.jms.ConnectionFactory。

连接工厂

所以要实现上面的就是我的 mule 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;
}

}



但是我得到了这个错误

。根异常是:不支持的 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

先感谢您。 任何建议都非常感谢。 谢谢和问候 尼维

【问题讨论】:

    标签: jms mule


    【解决方案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" />
    

    但是,请仔细考虑这样做的需要,原来的 activemq 连接器可能提供了您需要的几乎任何东西,除了连接缓存之外。如果这是您需要的,请考虑使用this。

    【讨论】:

      【解决方案2】:

      您正在使用 ActiveMQ 连接器,它需要 org.apache.activemq.ActiveMQConnectionFactory 类型的工厂类。如果你真的需要一个自定义工厂,你的 ConnectionFactoryImpl 类应该扩展 activemq 工厂:

      import org.apache.activemq.ActiveMQConnectionFactory;
      
      public class ConnectionFactoryImpl extends ActiveMQConnectionFactory {
      
          // Override the methods you need
      
      }
      

      然后你可以在连接器的connectionFactory-ref属性中引用它。

      【讨论】:

        【解决方案3】:

        如果您没有任何很好的理由(您没有在帖子中显示)编写自己的 ConenctionFactory 实现,您应该直接使用 JMS 提供者提供的实现。

        所以你应该使用这样的 bean 定义

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-02-12
          • 2015-12-13
          • 2014-04-23
          • 2015-07-19
          • 2019-08-24
          • 2015-07-01
          • 2020-10-20
          • 1970-01-01
          相关资源
          最近更新 更多