0

我已经集群了两台wildfly9服务器,我想在域模式下使用负载平衡和故障转移JMS功能,配置如下:

主 IP:192.168.1.1
从属 IP:192.168.1.2
hornetq ver 2.4.7
Wildfly 9

在 master 发生 while loop(send dummy msg) 故障转移期间,客户端连接确实切换到从属并抛出异常,为什么??我花了很多时间解决这个问题,仍然没有解决这个问题

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

从站配置如下:

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

我的客户代码如下:

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

当 Master/Slave Shutdown 时,客户端没有故障转移到另一台服务器,top 如何解决这个问题?先谢谢了

4

0 回答 0