0
votes

Could anyone suggest me how to configure connectionfactory in mule using connectionFactory-ref

I am trying to configure connectionfactory in mule using connectionFactory-ref[this is the url I am following ::: http://www.mulesoft.org/documentation-3.2/display/32X/JMS+Transport+Reference].

In the above mentioned documentation - mentioned - Configuring the ConnectionFactory

One of the most important attributes is connectionFactory-ref. This is a reference to the ConnectionFactory object which creates new connections for your JMS provider. The object must implement the interface javax.jms.ConnectionFactory.

ConnectionFactory

So to implement the above below is my 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>

Below java class

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;
}

}



However I am getting this error

. Root Exception was: Unsupported ConnectionFactory type: com.ers.connections.ConnectionFactoryImpl. Type: class java.lang.IllegalArgumentException ERROR 2014-12-28 11:53:26,141 [main] org.mule.module.launcher.application.DefaultMuleApplication: null java.lang.IllegalArgumentException: Unsupported ConnectionFactory type: com.ers.connections.ConnectionFactoryImpl

Thank you in advance. Any suggestions most appreciated. Thank you and regards Nivi

3

3 Answers

1
votes

If you don't have any really good reason, that you do not show in the post, to write your own ConenctionFactory implementation you should use the one provided by the JMS provider directly.

So you should use a bean definition like this

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

You are using the ActiveMQ connector and it is expecting a factory class of type org.apache.activemq.ActiveMQConnectionFactory. If you really need a custom factory, your ConnectionFactoryImpl class should extend the activemq factory:

import org.apache.activemq.ActiveMQConnectionFactory;

public class ConnectionFactoryImpl extends ActiveMQConnectionFactory {

    // Override the methods you need

}

Then you can reference it in connectionFactory-ref attribute of the connector.

1
votes

Your implementation probably does not provide any special feature, if this is the case please just use the default connector:

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

However if you have some special behaviour that you want to use, with the activemq connector, you just need a connection factory that implements org.apache.activemq.ActiveMQConnectionFactory, this is because these two lines. Then just use something like the following:

  <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" />

However please twink twice about the need of doing this, the original activemq connector probably provides almost anything you need with the exeption of connection caching. If that is what you need please consider using this.