blob: 1fcdcb719dbc1b3b147188f1559a2c9cf95d85c9 [file] [log] [blame]
<div class="wiki-content maincontent"><h2>How can I support auto reconnection?</h2>
<p>Networks are unreliable and sockets do get dropped from time to time (it could be a network glitch, dodgy router, firewall, or someone could even just restart a broker).</p>
<p>You often want a JMS client to automatically handle the fact that the connection to the broker was lost such that the JMS client either reconnnects to the same broker when it becomes available, or reconnects to another broker in the cluster.</p>
<p>Its easy to perform auto-reconnection. In Apache ActiveMQ using the <link><page ri:content-title="Failover Transport Reference"></page><link-body>failover transport</link-body></link> in which the JMS client (connection) will automatically reconnect to the broker if there is a socket exception. </p>
<p>Just use the following connection URI (setting the brokerURL in the ActiveMQConnectionFactory)</p>
<structured-macro ac:macro-id="b7cbcc04-7a5f-4161-8a80-f101a8c31ead" ac:name="code" ac:schema-version="1"><plain-text-body>
failover:tcp://host:port
</plain-text-body></structured-macro>
<p>You can use a list of URIs to specify which machines to connect to and use discovery to find the brokers to connect to. More details on this see <link><page ri:content-title="Configuring Transports"></page></link></p></div>