Java Code Examples for io.debezium.connector.base.ChangeEventQueue

Following code examples demonstrate how to use io.debezium.connector.base.ChangeEventQueue from debezium. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use io.debezium.connector.base.ChangeEventQueue and various code implementation of this class.
Example 1
Project : debezium Source File : View Source Code on GitHub

    public void start(Configuration config) {
        if (running.get()) {

        PostgresConnectorConfig connectorConfig = new PostgresConnectorConfig(config);

        TypeRegistry typeRegistry;
        try (final PostgresConnection connection = new PostgresConnection(connectorConfig.jdbcConfig())) {
            typeRegistry = connection.getTypeRegistry();

        TopicSelector topicSelector = TopicSelector.create(connectorConfig);
        PostgresSchema schema = new PostgresSchema(connectorConfig, typeRegistry, topicSelector);
        this.taskContext = new PostgresTaskContext(connectorConfig, schema, topicSelector);

        SourceInfo sourceInfo = new SourceInfo(connectorConfig.serverName());
        Map<String, Object> existingOffset = context.offsetStorageReader().offset(sourceInfo.partition());
        LoggingContext.PreviousContext previousContext = taskContext.configureLoggingContext(CONTEXT_NAME);
        try {
            try (PostgresConnection connection = taskContext.createConnection()) {

            if (existingOffset == null) {
      "No previous offset found");
                if (connectorConfig.snapshotNeverAllowed()) {
          "Snapshots are not allowed as per configuration, starting streaming logical changes only");
                    producer = new RecordsStreamProducer(taskContext, sourceInfo);
                } else {
                    createSnapshotProducer(taskContext, sourceInfo, connectorConfig.initialOnlySnapshot());
            } else {
      "Found previous offset {}", sourceInfo);
                if (sourceInfo.isSnapshotInEffect()) {
                    if (connectorConfig.snapshotNeverAllowed()) {
                        String msg = "The connector previously stopped while taking a snapshot, but now the connector is configured "
                                     + "to never allow snapshots. Reconfigure the connector to use snapshots initially or when needed.";
                        throw new ConnectException(msg);
                    } else {
              "Found previous incomplete snapshot");
                        createSnapshotProducer(taskContext, sourceInfo, connectorConfig.initialOnlySnapshot());
                } else if (connectorConfig.alwaysTakeSnapshot()) {
          "Taking a new snapshot as per configuration");
                    producer = new RecordsSnapshotProducer(taskContext, sourceInfo, true);
                } else {
                            "Previous snapshot has completed successfully, streaming logical changes from last known position");
                    producer = new RecordsStreamProducer(taskContext, sourceInfo);

            changeEventQueue = new ChangeEventQueue.Builder<ChangeEvent>()
                .loggingContextSupplier(() -> taskContext.configureLoggingContext(CONTEXT_NAME))

            producer.start(changeEventQueue::enqueue, changeEventQueue::producerFailure);
            running.compareAndSet(false, true);
        }  catch (SQLException e) {
            throw new ConnectException(e);
        } finally {