void writePayload(final Output output) {
        try {
            SearchProgressLog.increment(queryKey, SearchPhase.LMDB_DATA_STORE_WRITE_PAYLOAD);
            SimpleMetrics.measure("writePayload", () -> {
                try {
                    // Get the current payload.
                    final LmdbPayload payload = currentPayload.poll();
                    if (payload == null) {
                        // There will be 0 bytes to read so just write 0.
                        output.writeInt(0);

                    } else {
                        final byte[] data = payload.getData();
                        output.writeInt(data.length);
                        output.writeBytes(data);
                    }
                } catch (final KryoException e) {
                    // Expected as sometimes the output stream is closed by the receiving node.
                    LOGGER.debug(e::getMessage, e);
                } catch (final InterruptedException e) {
                    // Ensure we don't deliver further payloads.
                    currentPayload.terminate();

                    // There will be 0 bytes to read so just write 0.
                    output.writeInt(0);
                    LOGGER.trace(e::getMessage, e);
                    // Keep interrupting this thread.
                    Thread.currentThread().interrupt();
                } catch (final CompleteException e) {
                    // There will be 0 bytes to read so just write 0.
                    output.writeInt(0);
                    LOGGER.debug(() -> "Complete");
                    LOGGER.trace(e::getMessage, e);
                }
            });
        } catch (final RuntimeException e) {
            LOGGER.debug(e::getMessage, e);
        }
    }
Write data from the data store to an output removing them from the datastore as we go as they will be transferred
to another store.

@param output The output to write to.
stroom-query/stroom-query-common/src/main/java/stroom/query/common/v2/LmdbPayloadCreator.java