Package org.apache.ignite.cdc

## Interface CdcConsumer

-     public interface CdcConsumer

  Consumer of WAL data change events. This consumer will receive data change events during ignite-cdc process invocation. The lifecycle of the consumer is the following:
  - Start of the consumer `start(MetricRegistry)`.
  - Notification of the consumer by the `onEvents(Iterator)` call.
  - Stop of the consumer `stop()`.
  In case consumer implementation wants to use `IgniteLogger`, please, use, `LoggerResource` annotation:

       public class ChangeDataCaptureConsumer implements ChangeDataCaptureConsumer {
           @LoggerResource
           private IgniteLogger log;

           ...
       }

  Note, consumption of the `CdcEvent` will be started from the last saved offset. The offset of consumptions is saved on the disk every time `onEvents(Iterator)` returns `true`. Note, order of notifications are following:
  - `onMappings(Iterator)`
  - `onTypes(Iterator)`
  - `onCacheChange(Iterator)`
  - `onCacheDestroy(Iterator)`
  Note, `CdcConsumer` receive notifications on each running CDC application(node).
  See Also:
    `CdcEvent`, `CacheEntryVersion`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `default boolean` | `alive()` | Checks that consumer still alive.
    `void` | `onCacheChange​(Iterator<CdcCacheEvent> cacheEvents)` | Handles caches changes(create, edit) events.
    `void` | `onCacheDestroy​(Iterator<Integer> caches)` | Handles cache destroy events.
    `boolean` | `onEvents​(Iterator<CdcEvent> events)` | Handles entry changes events.
    `void` | `onMappings​(Iterator<TypeMapping> mappings)` | Handles new mappings from type name to id.
    `void` | `onTypes​(Iterator<BinaryType> types)` | Handles new binary types.
    `void` | `start​(MetricRegistry mreg)` | Starts the consumer.
    `void` | `stop()` | Stops the consumer.

- - ### Method Detail

    - #### start

          void start​(MetricRegistry mreg)

      Starts the consumer.
      Parameters:
        `mreg` - Metric registry for consumer specific metrics.

    - #### onEvents

          boolean onEvents​(Iterator<CdcEvent> events)

      Handles entry changes events. If this method return `true` then current offset will be stored and ongoing notifications after CDC application fail/restart will be started from it.
      Parameters:
        `events` - Entry change events.
      Returns:
        `True` if current offset should be saved on the disk to continue from it in case any failures or restart.

    - #### onTypes

          void onTypes​(Iterator<BinaryType> types)

      Handles new binary types. State of the types processing will be stored after method invocation and ongoing notifications after CDC application fail/restart will be continued for newly created/updates types. Note, unlike `onEvents(Iterator)` this method MUST process all types or CDC will fail. Because, in time of invocation `onEvents(Iterator)` all changed types must be available on destionation.
      Parameters:
        `types` - Binary types iterator.
      See Also:
        `IgniteBinary`, `IgniteBinary.type(int)`, `IgniteBinary.type(Class)`, `IgniteBinary.type(String)`, `IgniteBinary.types()`

    - #### onMappings

          void onMappings​(Iterator<TypeMapping> mappings)

      Handles new mappings from type name to id. State of the types processing will be stored after method invocation and ongoing notifications after CDC application fail/restart will be continued for newly created/updates mappings.
      Parameters:
        `mappings` - Binary mapping iterator.
      See Also:
        `IgniteBinary`, `IgniteBinary.typeId(String)`, `BinaryIdMapper`

    - #### onCacheChange

          void onCacheChange​(Iterator<CdcCacheEvent> cacheEvents)

      Handles caches changes(create, edit) events. State of cache processing will be stored after method invocation and ongoing notifications after CDC application fail/restart will be continued for newly changed caches.
      Parameters:
        `cacheEvents` - Cache change events.
      See Also:
        `Ignite.createCache(String)`, `Ignite.getOrCreateCache(String)`, `CdcCacheEvent`

    - #### onCacheDestroy

          void onCacheDestroy​(Iterator<Integer> caches)

      Handles cache destroy events. State of cache processing will be stored after method invocation and ongoing notifications after CDC application fail/restart will be continued for newly changed caches.
      Parameters:
        `caches` - Destroyed caches.
      See Also:
        `Ignite.destroyCache(String)`, `CdcCacheEvent`, `CacheView.cacheId()`

    - #### stop

          void stop()

      Stops the consumer. This method can be invoked only after `start(MetricRegistry)`.

    - #### alive

          default boolean alive()

      Checks that consumer still alive. This method helps to determine `CdcConsumer` errors in case `CdcEvent` is rare or source cluster is down.
      Returns:
        `True` in case consumer alive, `false` otherwise.