Creating a Maintenance Schedule for a Topic

For many applications, messages need to be removed at specific times (for example, at the end of a trading day, or when the message reaches a certain state) rather than having a message-specific time to live.

These applications typically configure a scheduled maintenance plan using AMPS actions to manage the SOW and remove unneeded information.

For full details on AMPS actions, see the Automating AMPS with Actions section in the user guide and the Actions section in the configuration reference.

Sample Maintenance Plan

Below is an example of a configuration section for a SOW topic definition, where records will need to be removed when they have reached a state of completed and been inactive for more than 24 hours. Since this is intended to manage the size of the saved state of the topic, it isn't necessary for messages to be removed precisely when they reach that state. Removing messages once a day, before activity begins for that day, is enough.

<SOW>
    <Topic>
        <Name>ORDERS</Name>
        <FileName>sow/%n.sow</FileName>
        <Key>/orderId</Key>
        <MessageType>nvfix</MessageType>
  </Topic>
</SOW>

To create this maintenance plan, we configure an AMPS action that runs at 02:00 local time and removes the messages that the topic no longer needs.

<Actions>
  <Action>
    <On>
      <Module>amps-action-on-schedule</Module>
      <Options>
        <Every>02:00</Every>
        <Name>Maintenance for ORDERS topic</Name>
      </Options>
    </On>
    <Do>
      <Module>amps-action-do-delete-sow</Module>
      <Options>
         <Topic>ORDERS</Topic>
         <MessageType>nvfix</MessageType>
         <Filter>/status = 'closed'
                 AND LAST_UPDATED() &lt; ({{AMPS_UNIX_TIMESTAMP}} - 86400)</Filter>
       </Options>
     </Do>
   </Action>
</Actions>

Notice that there are two parts to this action. The On element specifies when the action should run -- in this case, every day at 02:00 local time. The Do element directs AMPS to delete messages from the ORDERS topic (of message type nvfix) where the /status is closed, and where the last update for the message is earlier than 24 hours (86400 seconds) from the time the action was started. At the scheduled time, AMPS internally runs a sow_delete command that removes the specified messages. This command is also written to the transaction log and replicated to other instances.

With this configuration, AMPS can efficiently maintain the SOW topic based on the needs of the application.

Last updated

Copyright 2013-2024 60East Technologies, Inc.