Setting the Time-to-Live for Messages

When you create or edit a stream, you can specify the length of time for messages to exist in the stream before they expire.

Messages can persist in the partitions of a stream for as long as you need them to, and can be read or reread by consumers during that time. However, if you know that after a certain period of time the messages in a stream will no longer be needed, you can specify a length of time for messages to persist until they expire.

The default length of time is 604,800 seconds, or 7 days.

Expired messages are deleted by an automatic process that runs at periodic intervals of TTL/10, with a minimum of 24 hours. Examples:
  • If the TTL is set to 24 hours, expired messages are deleted once every 24 hours.
  • If the TTL is set to 7 days (i.e. 168 hours, which is the default), expired messages are deleted once every 24 hours because 24 is greater than 168/10.
  • If the TTL is set to 20 days (i.e 480 hours), expired messages are deleted once every 48 hours because 48 is greater than 24.

There are two methods that you can you to set this value if you are creating a stream, and two methods if the stream already exists:

When you are creating a stream

You can use a maprcli command or a Java API.

maprcli command
Use the -ttl parameter of the stream create command.
Java API
Use the Admin.createStream(String streamPathAndName, StreamDescriptor desc) API of the MapR Streams Java API library.
When you are editing a stream

Again, you can use a maprcli command or a Java API.

maprcli command
Use the -ttl parameter of the stream edit command.
Java API
Use the Admin.editStream(String streamPathAndName, StreamDescriptor desc) API of the MapR Streams Java API library.

If you want to delete expired messages immediately, you can run the maprcli command stream purge.