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