---
title:  Durable Message Replay
---

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

When the primary server receives the cache ready message, the servers and client execute a procedure to update the queue and replay the events from the stored messages.

Durable message replay proceeds as follows. To avoid overwriting current entries with old data, the client does not apply the updates to its cache.

1.  The server finds the queue for this durable client ID and updates its information, including the client’s socket and remote ports.

    If the client has timed out while it was disconnected, its queues are gone and the server then treats it as a new client. See [Initial Operation](initial-operation.html).

2.  All servers that have a queue for this client place a marker in the queue.

    Messages in the queue before the marker are considered to have come while the client was disconnected. Messages after the marker are handled normally.

3.  The cache server sends the queued messages to the client. This includes any messages that were evicted to disk.
4.  The client receives the messages but does not apply the updates to its cache. If cache listeners are installed, they handle the events. For implications, see [Implementing Cache Listeners for Durable Clients](impl-cache-listeners-durable-clients.html#concept_3BD651087FC4470C8BAB6AFD97AEA689).
5.  The client receives the marker message indicating that all past events have been played back.
6.  The cache server sends the current list of live regions.
7.  In each live region on the client, the marker event triggers the `afterRegionLive` callback.

    After the callback, the client begins normal processing of events from the server and applies the updates to its cache.

Even when a new client starts up for the first time, the cache ready markers are inserted in the queues. If messages start coming into the new queues before the servers insert the marker, those messages are considered as having happened while the client was disconnected, and their events are replayed the same as in the reconnect case.


