aeron

Aeron spy subscription


I want to publish data to Aeron even if there are no subscribers. I start media driver with a flag 'spiesSimulateConnection(true)'. Then I create a publication like this:

        if (isRecorded) {
            publication = archive.addRecordedExclusivePublication(channel, streamId);
        } else {
            publication = archive.context()
                .aeron()
                .addExclusivePublication(channel, streamId);
        }

If publication is recorded, then everything goes well. I understand that Aeron Archive creates a spy subscription, so the publication knows that someone is listening. If a publication is not recorded, then publication.offer returns Publication.NOT_CONNECTED. Is there a way to avoid errors here? Can I tell Aeron to create a spy subscription which discards data?


Solution

  • The NOT_CONNECTED isn't an error; it is an indication that there are no subscribers. If you want to discard data when there are no subscribers, then don't offer the message again, but drop it instead.