Class StreamingWal2JsonMessageDecoder

  • All Implemented Interfaces:
    MessageDecoder

    public class StreamingWal2JsonMessageDecoder
    extends AbstractMessageDecoder

    JSON deserialization of a message sent by wal2json logical decoding plugin. The plugin sends all changes in one transaction as a single batch and they are passed to processor one-by-one. The JSON file arrives in chunks of a big JSON file where the chunks are not valid JSON itself.

    There are four different chunks that can arrive from the decoder. Beginning of message

     {
       "xid": 563,
       "timestamp": "2018-03-20 10:58:43.396355+01",
       "change": [
     
    First change
          {
              "kind": "insert",
              "schema": "public",
              "table": "numeric_decimal_table",
              "columnnames": ["pk", "d", "dzs", "dvs", "d_nn", "n", "nzs", "nvs", "d_int", "dzs_int", "dvs_int", "n_int", "nzs_int", "nvs_int", "d_nan", "dzs_nan", "dvs_nan", "n_nan", "nzs_nan", "nvs_nan"],
              "columntypes": ["integer", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(6,4)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(6,4)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(6,4)", "numeric(4,0)", "numeric"],
              "columnoptionals": [false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
              "columnvalues": [1, 1.10, 10, 10.1111, 3.30, 22.2200, 22, 22.2222, 1.00, 10, 10, 22.0000, 22, 22, null, null, null, null, null, null]
          }
     
    Further changes
          ,{
              "kind": "insert",
              "schema": "public",
              "table": "numeric_decimal_table",
              "columnnames": ["pk", "d", "dzs", "dvs", "d_nn", "n", "nzs", "nvs", "d_int", "dzs_int", "dvs_int", "n_int", "nzs_int", "nvs_int", "d_nan", "dzs_nan", "dvs_nan", "n_nan", "nzs_nan", "nvs_nan"],
              "columntypes": ["integer", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(6,4)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(6,4)", "numeric(4,0)", "numeric", "numeric(3,2)", "numeric(4,0)", "numeric", "numeric(6,4)", "numeric(4,0)", "numeric"],
              "columnoptionals": [false, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
              "columnvalues": [1, 1.10, 10, 10.1111, 3.30, 22.2200, 22, 22.2222, 1.00, 10, 10, 22.0000, 22, 22, null, null, null, null, null, null]
          }
     
    End of message
          ]
     }
     

    For parsing purposes it is necessary to add or remove a fragment of JSON to make a well-formatted JSON out of it. The last message is just dropped.

    Author:
    Jiri Pechanec
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • containsMetadata

        private boolean containsMetadata
      • messageInProgress

        private boolean messageInProgress
      • currentChunk

        private byte[] currentChunk
        To identify if the last current chunk is the last one we can send the current one for processing only after we read the next one or the end of message fragment.
      • txId

        private long txId
      • commitTime

        private Instant commitTime
    • Constructor Detail

      • StreamingWal2JsonMessageDecoder

        public StreamingWal2JsonMessageDecoder()