Sunday, February 22, 2015

Configuration of eclipselink cache coordination in JBoss AS 7.1

Steps to configure eclipselink cache coordination in JBoss AS 7.1 

a.       Enable the JMX by adding useJmx=”true” at %APACHE_ACTIVEMQ_HOME%\conf\activemq.xml , so that consumer/producer or tha messages can be viewed through jconsole
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" useJmx="true">

2.     Persistence.xml
<property name="eclipselink.cache.coordination.naming-service" value="jndi"/>
<property name="eclipselink.cache.coordination.protocol" value="jms" />
<property name="eclipselink.cache.coordination.jms.topic" value="jms/OssCacheTopic" />
<property name="eclipselink.cache.coordination.jms.factory" value="jms/OssCacheTopicConnectionFactory" />
a.       Next we need to add active-mq module as shown at %JBOSS_HOME%\modules\activemq\activemq-all-5.9.0.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="activemq">
                <resources>
                                <resource-root path="activemq-all-5.9.0.jar"/>
                </resources>
                <dependencies>
                               <module name="javax.jms.api"/>
                </dependencies>
</module>
a.       Then we need to add eclipselink module if not already present or update the module entry for active-mq if already present %JBOSS_HOME%\modules\org\eclipse\eclipselink-2.5.0-RC1.jar
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
                <resources>
                                <resource-root path="eclipselink-2.5.0-RC1.jar"/>
                </resources>
                <dependencies>
                                <module name="asm.asm"/>
                                <module name="javax.api"/>
                                <module name="javax.jms.api"/>
                                <module name="activemq"/>
                                <module name="javax.persistence.api"/>
                                <module name="javax.transaction.api"/>
                                <module name="javax.validation.api"/>
                                                <module name="javax.xml.bind.api"/>
                                <module name="org.antlr"/>
                                <module name="org.apache.commons.collections"/>
                                <module name="org.dom4j"/>
                                <module name="org.javassist"/>
                                <module name="org.jboss.logging"/>
                </dependencies>
</module>
Then we need to add the resource adapter to JBoss for active-mq. For that we need to download the latest activemq-rar.rar and following changes has to be done and then modified activemq-rar.rar need to be deployed through JBoss admin console
a.       broker-config.xml – for embedded active this is needed, for non embedded , this file can be skipped
                                                               i.      Modify the activemq-rar\broker-config.xml as shown below
  <!--  shutdown hook is disabled as RAR classloader may be gone at shutdown -->
  <amq:broker xmlns="http://activemq.apache.org/schema/core" useShutdownHook="false" useJmx="true"
                 brokerName="localhost">
     <amq:managementContext>
       <!-- use appserver provided context instead of creating one,
            for jboss use: -Djboss.platform.mbeanserver -->
       <amq:managementContext createConnector="false"/>
     </amq:managementContext>
<!—commenting the data directory as it has to be non persistent topic-->
<!--
    <amq:persistenceAdapter>
       <amq:kahaDB directory="activemq-data/kahadb"/>
     </amq:persistenceAdapter> -->
    <amq:transportConnectors>
      <amq:transportConnector name="localhost" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>
    </amq:transportConnectors>   
  </amq:broker>
                                                              ii.      Then we need to modify the activemq-ra\META-INF\ra.xml as shown below
    <resourceadapter>
        <resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>
        <config-property>
            <description>
              The URL to the ActiveMQ server that you want this connection to connect to.  If using  an embedded broker, this value should be 'vm://localhost'.
            </description>
            <config-property-name>ServerUrl</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>tcp://localhost:61616/</config-property-value><!--
            <config-property-value>vm://localhost</config-property-value>-->
        </config-property>
        <config-property>
            <description>The default user name that will be used to establish connections to the ActiveMQ server.</description>
            <config-property-name>UserName</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>defaultUser</config-property-value>
        </config-property>
        <config-property>
            <description>The default password that will be used to log the default user into the ActiveMQ server.</description>
            <config-property-name>Password</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value>defaultPassword</config-property-value>
        </config-property>
        <config-property>
            <description>The client id that will be set on the connection that is established to the ActiveMQ server.</description>
            <config-property-name>Clientid</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
        </config-property>
        <config-property>
            <description>Boolean to configure if outbound connections should reuse the inbound connection's session for sending messages.</description>
            <config-property-name>UseInboundSession</config-property-name>
            <config-property-type>java.lang.Boolean</config-property-type>
           <config-property-value>false</config-property-value>
        </config-property>
                                                  <!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
        <config-property>
            <description>
              Sets the XML configuration file used to configure the embedded ActiveMQ broker
              Any valid URL string is supported.             
            </description>
            <config-property-name>BrokerXmlConfig</config-property-name>
            <config-property-type>java.lang.String</config-property-type>
            <config-property-value></config-property-value>
            <!--
             To use the broker-config.xml from the root for the RAR-->
               <config-property-value>xbean:broker-config.xml</config-property-value>                                                   <!--
             To use an external file or url location
               <config-property-value>xbean:file:///amq/config/jee/broker-config.xml</config-property-value>
            -->
        </config-property>
        <outbound-resourceadapter>
            <connection-definition>
                <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
                <connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>
                <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
                <connection-interface>javax.jms.Connection</connection-interface>
                <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
            </connection-definition>           
            <transaction-support>NoTransaction</transaction-support>
            <reauthentication-support>false</reauthentication-support>
        </outbound-resourceadapter>
        <inbound-resourceadapter>
            <messageadapter>
                <messagelistener>
                    <messagelistener-type>javax.jms.MessageListener</messagelistener-type>
                    <activationspec>
                        <activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>                       
                        <required-config-property>
                            <config-property-name>destination</config-property-name>
                        </required-config-property>
                        <required-config-property>
                            <config-property-name>destinationType</config-property-name>
                        </required-config-property>                       
                    </activationspec>
               </messagelistener>
            </messageadapter>
        </inbound-resourceadapter>
        <adminobject>
            <adminobject-interface>org.apache.activemq.command.ActiveMQQueue</adminobject-interface>
            <adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>
            <config-property>
                <config-property-name>PhysicalName</config-property-name>
                <config-property-type>java.lang.String</config-property-type>
            </config-property>
        </adminobject>
        <adminobject>
            <adminobject-interface>org.apache.activemq.command.ActiveMQTopic</adminobject-interface>
            <adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>
           <config-property>
                <config-property-name>PhysicalName</config-property-name>
                <config-property-type>java.lang.String</config-property-type>
            </config-property>
        </adminobject>
    </resourceadapter>
</connector>

                                                                                       i.      Then we have to add the ironjacamar.xml in the META_INF folder like activemq-ra\META-INF\ironjacamar.xml, and need to give all the topic and connection factory details

<?xml version="1.0" encoding="UTF-8"?>
<ironjacamar>
                <!-- This defines the ConnectionFactory bindings for JNDI -->
                <!-- disable  the definitions in the ra.xml except the basic ConnectionFactory -->
                <connection-definitions>
                                <connection-definition
                                                class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory"
                                                jndi-name="jms/OssCacheTopicConnectionFactory" pool-name="OssCacheTopicConnectionFactory">
                                                <pool>
                                                                <min-pool-size>1</min-pool-size>
                                                                <max-pool-size>200</max-pool-size>
                                                                <prefill>false</prefill>
                                                </pool>
                                                <security>
                                                                <application />
                                                </security>
                                                <timeout>
                                                                <blocking-timeout-millis>30000</blocking-timeout-millis>
                                                                <idle-timeout-minutes>3</idle-timeout-minutes>
                                                </timeout>
                                                <validation>
                                                                <background-validation>false</background-validation>
                                                                <use-fast-fail>false</use-fast-fail>
                                                </validation>
                                </connection-definition>
                </connection-definitions>
                <!-- Define your Topics/Queues here and specify a PhysicalName and a JNDI name -->
                <admin-objects>
                                <admin-object class-name="org.apache.activemq.command.ActiveMQTopic"
                                                jndi-name="jms/OssCacheTopic">
                                                <config-property name="PhysicalName">OssCacheTopic</config-property>
                                </admin-object>
                </admin-objects>
</ironjacamar>

No comments:

Post a Comment