0

I have clustered two wildfly9 servers, I want to use load-balancing and failover JMS feature in domain mode, config as below:

master ip: 192.168.1.1
slave ip: 192.168.1.2
hornetq ver 2.4.7
wildfly 9

During while loop (send dummy msg) failover occurs on master, client connection does switch to slave and throws exception, why?

<hornetq-server>
                    <clustered>true</clustered>
                    <cluster-password>my-pass</cluster-password>
                    <allow-failback>true</allow-failback>
                    <failover-on-shutdown>true</failover-on-shutdown>
                    <shared-store>false</shared-store>
                    <journal-file-size>102400</journal-file-size>

                    <connectors>
                        <netty-connector name="netty" socket-binding="messaging"/>
                        <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                            <param key="batch-delay" value="50"/>
                        </netty-connector>
                        <in-vm-connector name="in-vm" server-id="0"/>
                        <connector name="node1">
                            <param key="host" value="192.168.1.2"/>
                            <param key="port" value="5445"/>
                            <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
                        </connector>
                    </connectors>
<acceptors>
                        <netty-acceptor name="netty" socket-binding="messaging"/>
                        <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
                            <param key="batch-delay" value="50"/>
                            <param key="direct-deliver" value="false"/>
                        </netty-acceptor>
                        <in-vm-acceptor name="in-vm" server-id="0"/>
                    </acceptors>

                    <cluster-connections>
                        <cluster-connection name="my-cluster">
                            <address>jms</address>
                            <connector-ref>netty</connector-ref>
                            <check-period>1000</check-period>
                            <connection-ttl>1000</connection-ttl>
                            <reconnect-attempts>3</reconnect-attempts>
                            <static-connectors>
                                <connector-ref>
                                    node1
                                </connector-ref>
                            </static-connectors>
                        </cluster-connection>
                    </cluster-connections>

                    <security-settings>
                        <security-setting match="#">
                            <permission type="send" roles="guest"/>
                            <permission type="consume" roles="guest"/>
                            <permission type="createNonDurableQueue" roles="guest"/>
                            <permission type="deleteNonDurableQueue" roles="guest"/>
                        </security-setting>
                    </security-settings>

<address-settings>
                        <address-setting match="#">
                            <dead-letter-address>jms.queue.DLQ</dead-letter-address>
                            <expiry-address>jms.queue.ExpiryQueue</expiry-address>
                            <max-size-bytes>10485760</max-size-bytes>
                            <page-size-bytes>2097152</page-size-bytes>
                            <message-counter-history-day-limit>10</message-counter-history-day-limit>
                            <redistribution-delay>1000</redistribution-delay>
                        </address-setting>
                    </address-settings>

                    <jms-connection-factories>
                        <connection-factory name="InVmConnectionFactory">
                            <connectors>
                                <connector-ref connector-name="in-vm"/>
                            </connectors>
                            <entries>
                                <entry name="java:/ConnectionFactory"/>
                            </entries>
                        </connection-factory>
                        <connection-factory name="RemoteConnectionFactory">
                            <connectors>
                                <connector-ref connector-name="netty"/>
                            </connectors>
                            <entries>
                                <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                            </entries>
                            <ha>true</ha>
<block-on-durable-send>true</block-on-durable-send>
<block-on-acknowledge>true</block-on-acknowledge>
<connection-ttl>600000</connection-ttl>
<call-timeout>180000</call-timeout>
<client-failure-check-period>60000</client-failure-check-period>
<block-on-non-durable-send>true</block-on-non-durable-send>
<retry-interval>4000</retry-interval>
<reconnect-attempts>5</reconnect-attempts>
<confirmation-window-size>1000000</confirmation-window-size>
<consumer-window-size>3145728</consumer-window-size>

                        </connection-factory>
                        <pooled-connection-factory name="hornetq-ra">
                            <transaction mode="xa"/>
                            <connectors>
                                <connector-ref connector-name="in-vm"/>
                                <connector-ref connector-name="node1"/>
                            </connectors>
                            <entries>
                                <entry name="java:/JmsXA"/>
                                <entry name="java:jboss/DefaultJMSConnectionFactory"/>
                            </entries>
                            <ha>true</ha>
                            <block-on-acknowledge>true</block-on-acknowledge>
                            <reconnect-attempts>-1</reconnect-attempts>
                        </pooled-connection-factory>
                    </jms-connection-factories>

slave configuration as below:

 <hornetq-server>
                    <clustered>true</clustered>
                    <cluster-password>my-pass</cluster-password>
                    <shared-store>false</shared-store>
                    <journal-file-size>102400</journal-file-size>
                    <allow-failback>true</allow-failback>
                    <failover-on-shutdown>true</failover-on-shutdown>
                    <backup>true</backup>
                    <connectors>
                       <netty-connector name="netty" socket-binding="messaging"/>
                       <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                         <param key="batch-delay" value="50"/>
                        </netty-connector>
                        <in-vm-connector name="in-vm" server-id="1"/>
                        <connector name="node-master">
                           <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
                           <param key="host" value="192.168.1.1"/>
                          <param key="port" value="5445"/>
                        </connector>
                    </connectors>
<acceptors>
                       <netty-acceptor name="netty" socket-binding="messaging"/>
                       <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
                         <param key="batch-delay" value="50"/>
                         <param key="direct-deliver" value="false"/>
                       </netty-acceptor>
                       <in-vm-acceptor name="in-vm" server-id="1"/>
                     </acceptors>

                    <cluster-connections>
                        <cluster-connection name="my-cluster">
                            <address>jms</address>
                            <connector-ref>netty</connector-ref>
                            <reconnect-attempts>3</reconnect-attempts>
                            <connection-ttl>1000</connection-ttl>
                            <check-period>1000</check-period>
                            <static-connectors>
                                <connector-ref>node-master</connector-ref>
                            </static-connectors>
                        </cluster-connection>
                    </cluster-connections>
                    <security-settings>
                        <security-setting match="#">
                            <permission type="send" roles="guest"/>
                            <permission type="consume" roles="guest"/>
                            <permission type="createNonDurableQueue" roles="guest"/>
                            <permission type="deleteNonDurableQueue" roles="guest"/>
                        </security-setting>
                    </security-settings>

 </address-settings>
                    <jms-connection-factories>
                        <connection-factory name="InVmConnectionFactory">
                            <connectors>
                                <connector-ref connector-name="in-vm"/>
                            </connectors>
                            <entries>
                                <entry name="java:/ConnectionFactory"/>
                            </entries>
                        </connection-factory>
                        <connection-factory name="RemoteConnectionFactory">
                            <connectors>
                                <connector-ref connector-name="netty"/>
                            </connectors>
                            <entries>
                                <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                            </entries>
                            <block-on-acknowledge>true</block-on-acknowledge>
                             <ha>true</ha>
<block-on-durable-send>true</block-on-durable-send>
<block-on-acknowledge>true</block-on-acknowledge>
<connection-ttl>600000</connection-ttl>
<call-timeout>180000</call-timeout>
<client-failure-check-period>60000</client-failure-check-period>
<block-on-non-durable-send>true</block-on-non-durable-send>
<retry-interval>4000</retry-interval>
<reconnect-attempts>5</reconnect-attempts>
<confirmation-window-size>1000000</confirmation-window-size>
<consumer-window-size>3145728</consumer-window-size>

                        </connection-factory>

 <pooled-connection-factory name="hornetq-ra">
                            <transaction mode="xa"/>
                            <connectors>
                                <connector-ref connector-name="in-vm"/>
                                <connector-ref connector-name="node-master"/>
                            </connectors>
                            <entries>
                                <entry name="java:/JmsXA"/>
                                <!-- Global JNDI entry used to provide a default JMS Connection factory to EE application -->
                                <entry name="java:jboss/DefaultJMSConnectionFactory"/>
                            </entries>
                            <ha>true</ha>
                            <block-on-acknowledge>true</block-on-acknowledge>
                            <reconnect-attempts>-1</reconnect-attempts>
                        </pooled-connection-factory>
                    </jms-connection-factories>

my client code as below:

 Map<String, Object> connectionParams = new HashMap<String, Object>();
        connectionParams.put(TransportConstants.PORT_PROP_NAME, "port+port-offset");
        connectionParams.put(TransportConstants.HOST_PROP_NAME, "192.168.1.1");


        Map<String, Object> connectionParams2 = new HashMap<String, Object>();
        connectionParams2.put(TransportConstants.PORT_PROP_NAME, "port+port-offset");
        connectionParams2.put(TransportConstants.HOST_PROP_NAME, "192.168.1.2");


        TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);
        TransportConfiguration transportConfiguration1 = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams2);
        //



        HornetQConnectionFactory connectionFactory = HornetQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, transportConfiguration1, transportConfiguration);


        connectionFactory.setClientFailureCheckPeriod(1000);
        connectionFactory.setReconnectAttempts(3);
        connectionFactory.setConnectionTTL(1000);



        Connection connection = null;
        try {
            connection = connectionFactory.createConnection("username", "password");
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (connection != null) {
            System.out.println("JMS Connection succeed.");


        }
        // Step 9. create the JMS management queue.
        // It is a "special" queue and it is not looked up from JNDI but
        // constructed directly
        // see hornetq-jms.xml configuration file in server side
        Queue queue = HornetQJMSClient.createQueue("myQueue");

        Session session = null;
        try {
            session = connection.createSession(false, HornetQJMSConstants.PRE_ACKNOWLEDGE);
        } catch (JMSException e) {
            e.printStackTrace();
        }


        MessageProducer producer = null;
        try {
            producer = session.createProducer(queue);
        } catch (JMSException e) {
            e.printStackTrace();
        }
        
        while (true) {
            try {
                producer.send(session.createTextMessage("asdasdas"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

When Master/Slave Shutdown, client does not failover to another server, how to solve this problem?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Alireza Alallah
  • 2,486
  • 29
  • 35
  • The HornetQConnectionFactory is meant for plain JMS clients to connect to the broker. see[1] [1]https://developer.jboss.org/wiki/CanIUseTheSpringJMSTemplateWithHornetQ Also see https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/HornetQ_User_Guide/failover.html – Anup Dey Jun 12 '17 at 10:24
  • Thanks for response, `client-failure-check-period` does not works for me – Alireza Alallah Jun 12 '17 at 13:33
  • 1
    Since the client doesn't learn about the full topology until after the first connection is made there is a window where it doesn't know about the backup. If a failure happens at this point the client can only try reconnecting to the original live server. To configure how many attempts the client will make you can set the property initialConnectAttempts on the ClientSessionFactoryImpl or HornetQConnectionFactory or initial-connect-attempts in xml. The default for this is 0, that is try only once. Once the number of attempts has been made an exception will be thrown. – Anup Dey Jun 14 '17 at 12:42
  • For examples of automatic failover with transacted and non-transacted JMS sessions, see (https://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/examples.html#examples.transaction-failover) and (https://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/examples.html#examples.non-transaction-failover) – Anup Dey Jun 14 '17 at 12:42

0 Answers0