Message must be persistent
Master server configuration file:
Hornetq-configure.xml add
// Persistent configuration
<Persistence-enabled> true </persistence-enabled>
// Connector used to connect to the backup server
<Backup-connector-ref connector-name = "backup-connector"/>
<Connectors>
......
// Backup Connector
<Connector name = "backup-connector">
<Factory-class> org. hornetq. Core. remoting. impl. netty. nettyconnectorfactory </factory-class>
<Param key = "host" value = "172.20.16.191"/>
<Param key = "Port" value = "5445"/>
</Connector>
</Connectors>
Hornetq-jms.xml add
Add the property backup-connector-name in the connection-factory.connectors.connector-ref.
Add Failover-on-server-shutdown in connection-factory and set it to true, which indicates that the rescue will fail when Ctrl-C stops the server.
The specific configuration is as follows:
<Connection-factory name = "nettyconnectionfactory">
<Connectors>
<Connector-ref connector-name = "netty" backup-connector-name = "backup-connector"/>
</Connectors>
<Entries>
<Entry name = "connectionfactory"/>
<Entry name = "/xaconnectionfactory"/>
</Entries>
<Failover-on-server-Shutdown> true </failover-on-server-Shutdown>
</Connection-factory>
Slave server configuration file:
Hornetq-configure.xml add
// Persistent configuration
<Persistence-enabled> true </persistence-enabled>
// Whether it is a backup server
<Backup> true </backup>
Note:
1. Start the slave server first, and then start the master server.
2. Data on the master and slave sides must be consistent.
3. The above configuration uses data replication to ensure master-slave data consistency, there is also a way of storage sharing, the use of storage sharing is to add the following configuration in the master-slave server hornetq-configure.xml:
// Whether to share Storage
<Shared-store> true </Shared-store>
// Set the data directory to a shared directory
<Paging-directory> shared-DIR/data/paging </paging-directory>
<Bindings-directory> shared-DIR/data/bindings </bindings-directory>
<Journal-directory> shared-DIR/data/journal </Journal-directory>
<Large-messages-directory> shared-DIR/data/large-messages </large-messages-directory>