Interface ReplicationStream
- All Superinterfaces:
AutoCloseable
A stream from which messages sent by a logical decoding plugin can be consumed over a replication connection.
- Author:
- Horia Chiorean (hchiorea@redhat.com)
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()//TODO author=Horia Chiorean date=13/10/2016 description=Don't use this for now, because of the bug from the PG server This is stream is closed atm.voidSends a message to the server informing it about that latest position in the WAL that has successfully been processed.Returns the value for the latest server received LSN during a read operation.voidBlocks and waits for a replication message to be sent over a replication connection.booleanAttempts to read a replication message from a replication connection, processing that message if it's available or returningfalseif nothing is available.voidstartKeepAlive(ExecutorService service) Starts a background thread to ensure the slot is kept alive, useful for when temporarily stopping reads from the stream such as querying metadata, etcstartLsn()Returns the value for the LSN form which the streaming is executed.voidStops the background thread that is used to ensure the slot is kept alive.
-
Method Details
-
read
void read(ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Blocks and waits for a replication message to be sent over a replication connection. Once a message has been received, the value of thelast received LSNwill also be updated accordingly.- Parameters:
processor- - a callback to which the arrived message is passed- Throws:
SQLException- if anything unexpected failsInterruptedException- See Also:
-
PGReplicationStream.read()
-
readPending
boolean readPending(ReplicationStream.ReplicationMessageProcessor processor) throws SQLException, InterruptedException Attempts to read a replication message from a replication connection, processing that message if it's available or returningfalseif nothing is available. Once a message has been received, the value of thelast received LSNwill also be updated accordingly.- Parameters:
processor- - a callback to which the arrived message is passed- Returns:
trueif a message was received and processed- Throws:
SQLException- if anything unexpected failsInterruptedException- See Also:
-
PGReplicationStream.readPending()
-
flushLsn
Sends a message to the server informing it about that latest position in the WAL that has successfully been processed. Due to the internal buffering the messages sent to Kafka (and thus committed offsets) will usually lag behind the latest received LSN, which is why this method must only be called after the accompanying event has been sent to Kafka and the offset has been committed there.This essentially tells the server that this stream has successfully processed messages up to the current read cursor and so the server is free to discard older segments with earlier LSNs. It also affects the catch-up behavior once a slot is restarted and the server attempt to bring it up-to-date.
- Throws:
SQLException- if anything goes wrong
-
lastReceivedLsn
Lsn lastReceivedLsn()Returns the value for the latest server received LSN during a read operation. The value is always updated once messages are read via theReplicationConnection#startStreaming()orReplicationConnection#startStreaming(Long)methods.- Returns:
- a
Longvalue, possibly null if this is called before anything has been read
-
startLsn
Lsn startLsn()Returns the value for the LSN form which the streaming is executed.- Returns:
- a
Longvalue, possibly null if starting LSN is undefined
-
startKeepAlive
Starts a background thread to ensure the slot is kept alive, useful for when temporarily stopping reads from the stream such as querying metadata, etc -
stopKeepAlive
void stopKeepAlive()Stops the background thread that is used to ensure the slot is kept alive. -
close
//TODO author=Horia Chiorean date=13/10/2016 description=Don't use this for now, because of the bug from the PG server This is stream is closed atm. once the replication connection which created it is closed.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- See Also:
-
PGReplicationStream.close()
-