3 Replies Latest reply on Apr 3, 2018 1:12 PM by jbertram

    HornetQ static cluster not working

    pablorocha

      Hi

       

      I have a HornetQ running on machine A (server0), with the following configuration:

       

      <configuration xmlns="urn:hornetq"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
         
         <paging-directory>${data.dir:../data}/paging</paging-directory>
         
         <bindings-directory>${data.dir:../data}/bindings</bindings-directory>
         
         <journal-directory>${data.dir:../data}/journal</journal-directory>
         
         <journal-min-files>10</journal-min-files>
         
         <large-messages-directory>${data.dir:../data}/large-messages</large-messages-directory>
      
         <connectors>      
            <connector name="netty">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
            </connector>
            
            <connector name="netty-throughput">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
               <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
               <param key="batch-delay" value="50"/>
            </connector>
            
            <!-- connector to the server1 -->
             <connector name="server1-connector">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:172.22.10.33}"/>
               <param key="port" value="5445"/>
            </connector>
            
         </connectors>
      
         <acceptors>
            <acceptor name="netty">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:0.0.0.0}"/>
               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
            </acceptor>
            
            <acceptor name="netty-throughput">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:0.0.0.0}"/>
               <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
               <param key="batch-delay" value="50"/>
               <param key="direct-deliver" value="false"/>
            </acceptor>
         </acceptors>
      
         <!-- <broadcast-groups> -->
            <!-- <broadcast-group name="bg-group1"> -->
               <!-- <group-address>231.7.7.7</group-address> -->
               <!-- <group-port>9876</group-port> -->
               <!-- <broadcast-period>5000</broadcast-period> -->
               <!-- <connector-ref>netty</connector-ref> -->
            <!-- </broadcast-group> -->
         <!-- </broadcast-groups> -->
      
         <!-- <discovery-groups> -->
            <!-- <discovery-group name="dg-group1"> -->
               <!-- <group-address>231.7.7.7</group-address> -->
               <!-- <group-port>9876</group-port> -->
               <!-- <refresh-timeout>10000</refresh-timeout> -->
            <!-- </discovery-group> -->
         <!-- </discovery-groups> -->
         
         <cluster-connections>
            <cluster-connection name="my-cluster">
               <address>jms</address>     
               <connector-ref>netty</connector-ref>
                <static-connectors>
                  <connector-ref>server1-connector</connector-ref>
               </static-connectors>
            </cluster-connection>
         </cluster-connections>
         
         <security-settings>
            <security-setting match="#">
               <permission type="createNonDurableQueue" roles="guest"/>
               <permission type="deleteNonDurableQueue" roles="guest"/>
               <permission type="consume" roles="guest"/>
               <permission type="send" roles="guest"/>
            </security-setting>
         </security-settings>
      
         <address-settings>
            <!--default for catch all-->
            <address-setting match="#">
               <dead-letter-address>jms.queue.DLQ</dead-letter-address>
               <expiry-address>jms.queue.ExpiryQueue</expiry-address>
               <redelivery-delay>0</redelivery-delay>
               <max-size-bytes>10485760</max-size-bytes>       
               <message-counter-history-day-limit>10</message-counter-history-day-limit>
               <address-full-policy>BLOCK</address-full-policy>
            </address-setting>
         </address-settings>
      
         
      
      </configuration>
      
      

       

      I have another HornetQ running on machine B (server1), with the configuration below:

      <configuration xmlns="urn:hornetq"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
         
         <paging-directory>${data.dir:../data}/paging</paging-directory>
         
         <bindings-directory>${data.dir:../data}/bindings</bindings-directory>
         
         <journal-directory>${data.dir:../data}/journal</journal-directory>
         
         <journal-min-files>10</journal-min-files>
         
         <large-messages-directory>${data.dir:../data}/large-messages</large-messages-directory>
      
         <connectors>      
            <connector name="netty">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
            </connector>
            
            <connector name="netty-throughput">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
               <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
               <param key="batch-delay" value="50"/>
            </connector>
            
            <!-- connector to the server0 -->
             <connector name="server0-connector">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:172.22.9.7}"/>
               <param key="port" value="5445"/>
            </connector>
            
         </connectors>
      
         <acceptors>
            <acceptor name="netty">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:0.0.0.0}"/>
               <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
            </acceptor>
            
            <acceptor name="netty-throughput">
               <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
               <param key="host"  value="${hornetq.remoting.netty.host:0.0.0.0}"/>
               <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
               <param key="batch-delay" value="50"/>
               <param key="direct-deliver" value="false"/>
            </acceptor>
         </acceptors>
      
         <!-- <broadcast-groups> -->
            <!-- <broadcast-group name="bg-group1"> -->
               <!-- <group-address>231.7.7.7</group-address> -->
               <!-- <group-port>9876</group-port> -->
               <!-- <broadcast-period>5000</broadcast-period> -->
               <!-- <connector-ref>netty</connector-ref> -->
            <!-- </broadcast-group> -->
         <!-- </broadcast-groups> -->
      
         <!-- <discovery-groups> -->
            <!-- <discovery-group name="dg-group1"> -->
               <!-- <group-address>231.7.7.7</group-address> -->
               <!-- <group-port>9876</group-port> -->
               <!-- <refresh-timeout>10000</refresh-timeout> -->
            <!-- </discovery-group> -->
         <!-- </discovery-groups> -->
         
         <cluster-connections>
            <cluster-connection name="my-cluster">
               <address>jms</address>     
               <connector-ref>netty</connector-ref>
                <!-- <discovery-group-ref discovery-group-name="dg-group1"/> -->
                <static-connectors>
                  <connector-ref>server0-connector</connector-ref>
               </static-connectors>
            </cluster-connection>
         </cluster-connections>
         
         <security-settings>
            <security-setting match="#">
               <permission type="createNonDurableQueue" roles="guest"/>
               <permission type="deleteNonDurableQueue" roles="guest"/>
               <permission type="consume" roles="guest"/>
               <permission type="send" roles="guest"/>
            </security-setting>
         </security-settings>
      
         <address-settings>
            <!--default for catch all-->
            <address-setting match="#">
               <dead-letter-address>jms.queue.DLQ</dead-letter-address>
               <expiry-address>jms.queue.ExpiryQueue</expiry-address>
               <redelivery-delay>0</redelivery-delay>
               <max-size-bytes>10485760</max-size-bytes>       
               <message-counter-history-day-limit>10</message-counter-history-day-limit>
               <address-full-policy>BLOCK</address-full-policy>
            </address-setting>
         </address-settings>
      
         
      
      </configuration>
      
      

       

      As I researched, the Load Balancer Client Side was supposed to be working because the HornetQ would be a cluster.

       

      The problem is that the Load Balancer Client Side does not work.

       

      My questions are:

       

      Is there something wrong with setting up hornetq-configuration.xml? Should the cluster be working?

       

      If the configuration of these files is correct, what do I have to do in order to have an load Balancer Client Side?

       

      On the client side I have the following configuration:

      <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
            <property name="failoverOnInitialConnection" value="true"/>
            <property name="clientFailureCheckPeriod" value="10000"/>
            <constructor-arg name="ha" value="true" />
            <constructor-arg>
              <list>
                   <bean class="org.hornetq.api.core.TransportConfiguration">
                      <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                      <constructor-arg>
                         <map key-type="java.lang.String" value-type="java.lang.Object">
                            <!-- HornetQ standalone instance details -->
                            <entry key="host" value="172.22.10.33" />
                            <entry key="port" value="5445" />
                         </map>
                      </constructor-arg>
                   </bean>
                    <bean class="org.hornetq.api.core.TransportConfiguration">
                      <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                      <constructor-arg>
                         <map key-type="java.lang.String" value-type="java.lang.Object">
                            <!-- HornetQ standalone instance details -->
                            <entry key="host" value="localhost"/>
                            <entry key="port" value="5445" />
                         </map>
                      </constructor-arg>
                   </bean>
               </list>
            </constructor-arg>
         </bean>
      

       

      Could someone help me?

       

      Thank you very much in advance.

        • 1. Re: HornetQ static cluster not working
          jbertram

          The problem is that the Load Balancer Client Side does not work.

          Can you elaborate on what exactly isn't working? Do you have any sample code you can provide to demonstrate what the client is doing when things aren't working?

           

          Is there something wrong with setting up hornetq-configuration.xml? Should the cluster be working?

          The configuration looks fine as far as I can tell.

           

          If the configuration of these files is correct, what do I have to do in order to have an load Balancer Client Side?

          The main thing to keep in mind is that multiple connections from the same connection factory instance have to be created in order for the connection load-balancing policy to really take effect. Is that happening in your use-case?

          • 2. Re: HornetQ static cluster not working
            pablorocha

            Can you elaborate on what exactly isn't working? Do you have any sample code you can provide to demonstrate what the client is doing when things aren't working?

            When messages are being sent from ActivieMQ to HornetQ, messages are being sent only to HornetQ instance A.

             

            The client is the ActiveMQ. I'm using the configuration below to connect with the HornetQ:

             

            <!-- HornetQ -->
               <bean name="hornetq" class="org.apache.camel.component.jms.JmsComponent">
                  <property name="connectionFactory" ref="connectionFactory" />
               </bean>
               <!-- ConnectionFactory Definition -->
               <bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
                  <constructor-arg ref="hornetConnectionFactory" />
               </bean>
               
               <bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
                  <property name="failoverOnInitialConnection" value="true"/>
                  <property name="clientFailureCheckPeriod" value="10000"/>
                  <constructor-arg name="ha" value="true" />
                  <constructor-arg>
                    <list>
                         <bean class="org.hornetq.api.core.TransportConfiguration">
                            <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                            <constructor-arg>
                               <map key-type="java.lang.String" value-type="java.lang.Object">
                                  <!-- HornetQ standalone instance details -->
                                  <entry key="host" value="172.22.10.33" />
                                  <entry key="port" value="5445" />
                               </map>
                            </constructor-arg>
                         </bean>
                          <bean class="org.hornetq.api.core.TransportConfiguration">
                            <constructor-arg value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                            <constructor-arg>
                               <map key-type="java.lang.String" value-type="java.lang.Object">
                                  <!-- HornetQ standalone instance details -->
                                  <entry key="host" value="localhost"/>
                                  <entry key="port" value="5445" />
                               </map>
                            </constructor-arg>
                         </bean>
                     </list>
                  </constructor-arg>
               </bean>
            </beans>
            

             

            The IP 172.22.10.33 is referring to instance B of HornetQ. Localhost is referring to HornetQ A.

             

            The main thing to keep in mind is that multiple connections from the same connection factory instance have to be created in order for the connection load-balancing policy to really take effect. Is that happening in your use-case?

            I do not know responder this. How could I check?

            • 3. Re: HornetQ static cluster not working
              jbertram

              The client is the ActiveMQ. I'm using the configuration below to connect with the HornetQ...

              I'm confused on the role ActiveMQ is playing in your use-case.  Can you clarify this?

               

              If your client is only making a single connection but you still want the messages to be distributed evenly between the cluster nodes then you can set <forward-when-no-consumers>true</forward-when-no-consumers> on your <cluster-connection>.  Read more about this in the clustering documentation.