@TriggerSerially @PrimaryNodeOnly @InputRequirement(value=INPUT_FORBIDDEN) @Tags(value={"sql","jdbc","cdc","mysql"}) @CapabilityDescription(value="Retrieves Change Data Capture (CDC) events from a MySQL database. CDC Events include INSERT, UPDATE, DELETE operations. Events are output as individual flow files ordered by the time at which the operation occurred.") @Stateful(scopes=CLUSTER, description="Information such as a \'pointer\' to the current CDC event in the database is stored by this processor, such that it can continue from the same location if restarted.") @WritesAttribute(attribute="cdc.sequence.id",description="A sequence identifier (i.e. strictly increasing integer value) specifying the order of the CDC event flow file relative to the other event flow file(s).") @WritesAttribute(attribute="cdc.event.type",description="A string indicating the type of CDC event that occurred, including (but not limited to) \'begin\', \'insert\', \'update\', \'delete\', \'ddl\' and \'commit\'.") @WritesAttribute(attribute="mime.type",description="The processor outputs flow file content in JSON format, and sets the mime.type attribute to application/json") public class CaptureChangeMySQL extends AbstractSessionFactoryProcessor
| Modifier and Type | Class and Description |
|---|---|
private static class |
CaptureChangeMySQL.DriverShim |
private class |
CaptureChangeMySQL.JDBCConnectionHolder |
| Constructor and Description |
|---|
CaptureChangeMySQL() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearState() |
protected void |
connect(List<InetSocketAddress> hosts,
String username,
String password,
Long serverId,
boolean createEnrichmentConnection,
String driverLocation,
String driverName,
long connectTimeout,
SSLContextService sslContextService,
com.github.shyiko.mysql.binlog.network.SSLMode sslMode) |
(package private) com.github.shyiko.mysql.binlog.BinaryLogClient |
createBinlogClient(String hostname,
int port,
String username,
String password) |
(package private) BinlogEventListener |
createBinlogEventListener(com.github.shyiko.mysql.binlog.BinaryLogClient client,
LinkedBlockingQueue<RawBinlogEvent> q)
Creates and returns a BinlogEventListener instance, associated with the specified binlog client and event queue.
|
(package private) BinlogLifecycleListener |
createBinlogLifecycleListener()
Creates and returns a BinlogLifecycleListener instance, associated with the specified binlog client and event queue.
|
protected Collection<ValidationResult> |
customValidate(ValidationContext validationContext) |
private List<InetSocketAddress> |
getHosts(String hostsString)
Get a list of hosts from a NiFi property, e.g.
|
protected Connection |
getJdbcConnection() |
Set<Relationship> |
getRelationships() |
protected List<PropertyDescriptor> |
getSupportedPropertyDescriptors() |
protected TableInfo |
loadTableInfo(TableInfoCacheKey key)
Retrieves the column information for the specified database and table.
|
void |
onPrimaryNodeChange(PrimaryNodeState state) |
void |
onStopped(ProcessContext context) |
void |
onTrigger(ProcessContext context,
ProcessSessionFactory sessionFactory) |
void |
outputEvents(ProcessSession session,
ComponentLog log) |
protected void |
registerDriver(String locationString,
String drvName)
using Thread.currentThread().getContextClassLoader(); will ensure that you are using the ClassLoader for you NAR.
|
void |
setup(ProcessContext context) |
protected void |
stop() |
private void |
updateState(ProcessSession session) |
private void |
updateState(ProcessSession session,
String binlogFile,
long binlogPosition,
long sequenceId,
String gtidSet) |
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrueequals, getPropertyDescriptor, getPropertyDescriptors, getSupportedDynamicPropertyDescriptor, hashCode, onPropertyModified, validateclone, finalize, getClass, notify, notifyAll, wait, wait, waitisStatefulgetPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validateprivate static final int DO_NOT_SET
public static final Relationship REL_SUCCESS
protected static Set<Relationship> relationships
private static final AllowableValue SSL_MODE_DISABLED
private static final AllowableValue SSL_MODE_PREFERRED
private static final AllowableValue SSL_MODE_REQUIRED
private static final AllowableValue SSL_MODE_VERIFY_IDENTITY
public static final PropertyDescriptor DATABASE_NAME_PATTERN
public static final PropertyDescriptor TABLE_NAME_PATTERN
public static final PropertyDescriptor CONNECT_TIMEOUT
public static final PropertyDescriptor HOSTS
public static final PropertyDescriptor DRIVER_NAME
public static final PropertyDescriptor DRIVER_LOCATION
public static final PropertyDescriptor USERNAME
public static final PropertyDescriptor PASSWORD
public static final PropertyDescriptor SERVER_ID
public static final PropertyDescriptor DIST_CACHE_CLIENT
public static final PropertyDescriptor RETRIEVE_ALL_RECORDS
public static final PropertyDescriptor INCLUDE_BEGIN_COMMIT
public static final PropertyDescriptor INCLUDE_DDL_EVENTS
public static final PropertyDescriptor STATE_UPDATE_INTERVAL
public static final PropertyDescriptor INIT_SEQUENCE_ID
public static final PropertyDescriptor INIT_BINLOG_FILENAME
public static final PropertyDescriptor INIT_BINLOG_POSITION
public static final PropertyDescriptor USE_BINLOG_GTID
public static final PropertyDescriptor INIT_BINLOG_GTID
public static final PropertyDescriptor SSL_MODE
public static final PropertyDescriptor SSL_CONTEXT_SERVICE
private static final List<PropertyDescriptor> propDescriptors
private volatile ProcessSession currentSession
private com.github.shyiko.mysql.binlog.BinaryLogClient binlogClient
private BinlogEventListener eventListener
private BinlogLifecycleListener lifecycleListener
private com.github.shyiko.mysql.binlog.GtidSet gtidSet
private final LinkedBlockingQueue<RawBinlogEvent> queue
private volatile String currentBinlogFile
private volatile long currentBinlogPosition
private volatile String currentGtidSet
private volatile String xactBinlogFile
private volatile long xactBinlogPosition
private volatile long xactSequenceId
private volatile String xactGtidSet
private volatile TableInfo currentTable
private volatile String currentDatabase
private volatile Pattern databaseNamePattern
private volatile Pattern tableNamePattern
private volatile boolean includeBeginCommit
private volatile boolean includeDDLEvents
private volatile boolean useGtid
private volatile boolean inTransaction
private volatile boolean skipTable
private final AtomicBoolean doStop
private final AtomicBoolean hasRun
private int currentHost
private String transitUri
private final AtomicLong currentSequenceId
private volatile DistributedMapCacheClient cacheClient
private final Serializer<TableInfoCacheKey> cacheKeySerializer
private final Serializer<TableInfo> cacheValueSerializer
private final Deserializer<TableInfo> cacheValueDeserializer
private CaptureChangeMySQL.JDBCConnectionHolder jdbcConnectionHolder
private final BeginTransactionEventWriter beginEventWriter
private final CommitTransactionEventWriter commitEventWriter
private final DDLEventWriter ddlEventWriter
private final InsertRowsWriter insertRowsWriter
private final DeleteRowsWriter deleteRowsWriter
private final UpdateRowsWriter updateRowsWriter
public Set<Relationship> getRelationships()
getRelationships in interface ProcessorgetRelationships in class AbstractSessionFactoryProcessorprotected List<PropertyDescriptor> getSupportedPropertyDescriptors()
getSupportedPropertyDescriptors in class AbstractConfigurableComponentprotected Collection<ValidationResult> customValidate(ValidationContext validationContext)
customValidate in class AbstractConfigurableComponent@OnPrimaryNodeStateChange public void onPrimaryNodeChange(PrimaryNodeState state) throws CDCException
CDCExceptionpublic void setup(ProcessContext context)
public void onTrigger(ProcessContext context, ProcessSessionFactory sessionFactory) throws ProcessException
ProcessException@OnStopped @OnShutdown public void onStopped(ProcessContext context)
private List<InetSocketAddress> getHosts(String hostsString)
hostsString - A comma-separated list of hosts (host:port,host2:port2, etc.)protected void connect(List<InetSocketAddress> hosts, String username, String password, Long serverId, boolean createEnrichmentConnection, String driverLocation, String driverName, long connectTimeout, SSLContextService sslContextService, com.github.shyiko.mysql.binlog.network.SSLMode sslMode) throws IOException
IOExceptionpublic void outputEvents(ProcessSession session, ComponentLog log) throws IOException
IOExceptionprotected void clearState()
throws IOException
IOExceptionprotected void stop()
throws CDCException
CDCExceptionprivate void updateState(ProcessSession session) throws IOException
IOExceptionprivate void updateState(ProcessSession session, String binlogFile, long binlogPosition, long sequenceId, String gtidSet) throws IOException
IOExceptionBinlogEventListener createBinlogEventListener(com.github.shyiko.mysql.binlog.BinaryLogClient client, LinkedBlockingQueue<RawBinlogEvent> q)
client - A reference to a BinaryLogClient. The listener is associated with the given client, such that the listener is notified when
events are available to the given client.q - A queue used to communicate events between the listener and the NiFi processor thread.BinlogLifecycleListener createBinlogLifecycleListener()
com.github.shyiko.mysql.binlog.BinaryLogClient createBinlogClient(String hostname, int port, String username, String password)
protected TableInfo loadTableInfo(TableInfoCacheKey key) throws SQLException
key - A TableInfoCacheKey reference, which contains the database and table namesSQLExceptionprotected Connection getJdbcConnection() throws SQLException
SQLExceptionprotected void registerDriver(String locationString, String drvName) throws InitializationException
InitializationException - if there is a problem obtaining the ClassLoaderCopyright © 2022 Apache NiFi Project. All rights reserved.