@TriggerSerially @PrimaryNodeOnly @InputRequirement(value=INPUT_FORBIDDEN) @Tags(value={"sql","jdbc","cdc","mysql","transaction","event"}) @CapabilityDescription(value="Retrieves Change Data Capture (CDC) events from a MySQL database. CDC Events include INSERT, UPDATE, DELETE operations. Events are output as either a group of a specified number of events (the default is 1 so each event becomes its own flow file) or grouped as a full transaction (BEGIN to COMMIT). All events are ordered by the time at which the operation occurred. NOTE: If the processor is stopped before the specified number of events have been written to a flow file, the partial flow file will be output in order to maintain the consistency of the event stream.") @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") @RequiresInstanceClassLoading @Restricted(restrictions=@Restriction(requiredPermission=REFERENCE_REMOTE_RESOURCES,explanation="Database Driver Location can reference resources over HTTP")) public class CaptureChangeMySQL extends AbstractSessionFactoryProcessor
| Modifier and Type | Class and Description |
|---|---|
static class |
CaptureChangeMySQL.BinlogEventState |
static class |
CaptureChangeMySQL.BinlogResourceInfo |
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,
String driverLocation,
String driverName,
long connectTimeout,
SSLContextService sslContextService,
com.github.shyiko.mysql.binlog.network.SSLMode sslMode) |
protected 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,
BlockingQueue<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() |
private boolean |
isQueryDDL(String sql) |
protected TableInfo |
loadTableInfo(TableInfoCacheKey key)
Retrieves the column information for the specified database and table.
|
protected String |
normalizeQuery(String sql) |
void |
onPrimaryNodeChange(PrimaryNodeState state) |
void |
onTrigger(ProcessContext context,
ProcessSessionFactory sessionFactory) |
void |
outputEvents(ProcessSession session,
ProcessContext context,
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) |
void |
stop() |
private void |
updateState(ProcessSession session,
DataCaptureState dataCaptureState) |
private void |
updateState(ProcessSession session,
DataCaptureState dataCaptureState,
boolean inTransaction) |
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
private static final int DEFAULT_MYSQL_PORT
private static final Pattern MULTI_COMMENT_PATTERN
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 EVENTS_PER_FLOWFILE_STRATEGY
public static final PropertyDescriptor NUMBER_OF_EVENTS_PER_FLOWFILE
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 com.github.shyiko.mysql.binlog.BinaryLogClient binlogClient
private volatile BinlogEventListener eventListener
private volatile BinlogLifecycleListener lifecycleListener
private volatile com.github.shyiko.mysql.binlog.GtidSet gtidSet
private final BlockingQueue<RawBinlogEvent> queue
private final Map<TableInfoCacheKey,TableInfo> tableInfoCache
private volatile ProcessSession currentSession
private DataCaptureState currentDataCaptureState
private volatile CaptureChangeMySQL.BinlogResourceInfo binlogResourceInfo
private volatile Pattern databaseNamePattern
private volatile Pattern tableNamePattern
private volatile boolean skipTable
private int currentHost
private volatile CaptureChangeMySQL.JDBCConnectionHolder jdbcConnectionHolder
private final CaptureChangeMySQL.BinlogEventState binlogEventState
private final BeginEventHandler beginEventHandler
private final CommitEventHandler commitEventHandler
private final DDLEventHandler ddlEventHandler
private final InsertEventHandler insertEventHandler
private final DeleteEventHandler deleteEventHandler
private final UpdateEventHandler updateEventHandler
private volatile EventWriterConfiguration eventWriterConfiguration
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
ProcessExceptionprivate 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, String driverLocation, String driverName, long connectTimeout, SSLContextService sslContextService, com.github.shyiko.mysql.binlog.network.SSLMode sslMode) throws IOException
IOExceptionpublic void outputEvents(ProcessSession session, ProcessContext context, ComponentLog log) throws IOException
IOExceptionprivate boolean isQueryDDL(String sql)
protected void clearState()
throws IOException
IOException@OnStopped public void stop() throws CDCException
CDCExceptionprivate void updateState(ProcessSession session, DataCaptureState dataCaptureState) throws IOException
IOExceptionprivate void updateState(ProcessSession session, DataCaptureState dataCaptureState, boolean inTransaction) throws IOException
IOExceptionBinlogEventListener createBinlogEventListener(com.github.shyiko.mysql.binlog.BinaryLogClient client, BlockingQueue<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()
protected 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 © 2023 Apache NiFi Project. All rights reserved.