use of io.debezium.connector.postgresql.connection.ReplicationMessage in project debezium by debezium.
the class RecordsStreamProducer method process.
private void process(ReplicationMessage message, Long lsn, BlockingConsumer<ChangeEvent> consumer) throws SQLException, InterruptedException {
if (message == null) {
// in some cases we can get null if PG gives us back a message earlier than the latest reported flushed LSN
return;
}
TableId tableId = PostgresSchema.parse(message.getTable());
assert tableId != null;
// update the source info with the coordinates for this message
long commitTimeNs = message.getCommitTime();
long txId = message.getTransactionId();
sourceInfo.update(lsn, commitTimeNs, txId);
if (logger.isDebugEnabled()) {
logger.debug("received new message at position {}\n{}", ReplicationConnection.format(lsn), message);
}
TableSchema tableSchema = tableSchemaFor(tableId);
if (tableSchema == null) {
return;
}
if (tableSchema.keySchema() == null) {
logger.warn("ignoring message for table '{}' because it does not have a primary key defined", tableId);
}
ReplicationMessage.Operation operation = message.getOperation();
switch(operation) {
case INSERT:
{
Object[] row = columnValues(message.getNewTupleList(), tableId, true, message.hasTypeMetadata());
generateCreateRecord(tableId, row, message.isLastEventForLsn(), consumer);
break;
}
case UPDATE:
{
Object[] newRow = columnValues(message.getNewTupleList(), tableId, true, message.hasTypeMetadata());
Object[] oldRow = columnValues(message.getOldTupleList(), tableId, false, message.hasTypeMetadata());
generateUpdateRecord(tableId, oldRow, newRow, message.isLastEventForLsn(), consumer);
break;
}
case DELETE:
{
Object[] row = columnValues(message.getOldTupleList(), tableId, false, message.hasTypeMetadata());
generateDeleteRecord(tableId, row, message.isLastEventForLsn(), consumer);
break;
}
default:
{
logger.warn("unknown message operation: " + operation);
}
}
}
Aggregations