-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from networknt/refactor
Refactor polling cdc for oracle as required by user
- Loading branch information
Showing
22 changed files
with
770 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...lling/src/main/java/com/networknt/eventuate/cdc/polling/PollingCdcServiceInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.networknt.eventuate.cdc.polling; | ||
|
||
import com.networknt.config.Config; | ||
import com.networknt.eventuate.jdbc.EventuateSchema; | ||
import com.networknt.eventuate.kafka.KafkaConfig; | ||
import com.networknt.eventuate.kafka.producer.EventuateKafkaProducer; | ||
import com.networknt.eventuate.server.common.*; | ||
import com.networknt.service.SingletonServiceFactory; | ||
import org.apache.curator.RetryPolicy; | ||
import org.apache.curator.framework.CuratorFramework; | ||
import org.apache.curator.framework.CuratorFrameworkFactory; | ||
import org.apache.curator.retry.ExponentialBackoffRetry; | ||
|
||
import javax.sql.DataSource; | ||
|
||
|
||
public class PollingCdcServiceInitializer { | ||
|
||
public static String CDC_CONFIG_NAME = "cdc"; | ||
public static CdcConfig cdcConfig = (CdcConfig) Config.getInstance().getJsonObjectConfig(CDC_CONFIG_NAME, CdcConfig.class); | ||
public static String KAFKA_CONFIG_NAME = "kafka"; | ||
public static KafkaConfig kafkaConfig = (KafkaConfig) Config.getInstance().getJsonObjectConfig(KAFKA_CONFIG_NAME, KafkaConfig.class); | ||
|
||
public EventuateSchema eventuateSchema() { | ||
return new EventuateSchema(); | ||
} | ||
|
||
|
||
|
||
public PollingDao pollingDao() { | ||
DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class); | ||
EventPollingDataProvider pollingDataProvider= (EventPollingDataProvider) SingletonServiceFactory.getBean(EventPollingDataProvider.class); | ||
|
||
return new PollingDao (pollingDataProvider, ds, | ||
cdcConfig.getMaxEventsPerPolling(), | ||
cdcConfig.getMaxAttemptsForPolling(), | ||
cdcConfig.getPollingRetryIntervalInMilliseconds()); | ||
} | ||
|
||
public EventuateKafkaProducer eventuateKafkaProducer() { | ||
return new EventuateKafkaProducer(); | ||
} | ||
|
||
|
||
|
||
public CdcProcessor<PublishedEvent> pollingCdcProcessor() { | ||
PollingDao pollingDao = SingletonServiceFactory.getBean(PollingDao.class); | ||
return new PollingCdcProcessor<>(pollingDao, cdcConfig.getPollingIntervalInMilliseconds()); | ||
} | ||
|
||
public CdcKafkaPublisher<PublishedEvent> pollingCdcKafkaPublisher() { | ||
PublishingStrategy<PublishedEvent> publishingStrategy = SingletonServiceFactory.getBean(PublishingStrategy.class); | ||
return new PollingCdcKafkaPublisher<>( kafkaConfig.getBootstrapServers(), publishingStrategy); | ||
} | ||
|
||
public CuratorFramework curatorFramework() { | ||
String connectionString = cdcConfig.getZookeeper(); | ||
return makeStartedCuratorClient(connectionString); | ||
} | ||
|
||
public EventTableChangesToAggregateTopicTranslator<PublishedEvent> pollingEventTableChangesToAggregateTopicTranslator() { | ||
CdcKafkaPublisher<PublishedEvent> mySQLCdcKafkaPublisher = SingletonServiceFactory.getBean(CdcKafkaPublisher.class); | ||
CdcProcessor<PublishedEvent> mySQLCdcProcessor = SingletonServiceFactory.getBean(CdcProcessor.class); | ||
CuratorFramework curatorFramework = SingletonServiceFactory.getBean(CuratorFramework.class); | ||
|
||
return new EventTableChangesToAggregateTopicTranslator<>(mySQLCdcKafkaPublisher, | ||
mySQLCdcProcessor, | ||
curatorFramework, | ||
cdcConfig); | ||
} | ||
|
||
static CuratorFramework makeStartedCuratorClient(String connectionString) { | ||
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); | ||
CuratorFramework client = CuratorFrameworkFactory. | ||
builder().retryPolicy(retryPolicy) | ||
.connectString(connectionString) | ||
.build(); | ||
client.start(); | ||
return client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...dc-connector-polling/src/test/java/com/networknt/eventute/cdc/polling/PollingDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.networknt.eventute.cdc.polling; | ||
|
||
|
||
import com.networknt.eventuate.cdc.polling.EventPollingDataProvider; | ||
import com.networknt.eventuate.cdc.polling.PollingDao; | ||
|
||
import com.networknt.eventuate.server.common.PublishedEvent; | ||
import com.networknt.service.SingletonServiceFactory; | ||
import org.h2.tools.RunScript; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
/** | ||
* Junit test class for MessageProducerJdbcImpl. | ||
* use H2 test database for data source | ||
*/ | ||
public class PollingDaoTest { | ||
|
||
public static DataSource ds; | ||
|
||
static { | ||
ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class); | ||
try (Connection connection = ds.getConnection()) { | ||
// Runscript doesn't work need to execute batch here. | ||
String schemaResourceName = "/eventuate_sourcing_ddl.sql"; | ||
InputStream in = PollingDaoTest.class.getResourceAsStream(schemaResourceName); | ||
|
||
if (in == null) { | ||
throw new RuntimeException("Failed to load resource: " + schemaResourceName); | ||
} | ||
InputStreamReader reader = new InputStreamReader(in); | ||
RunScript.execute(connection, reader); | ||
|
||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private EventPollingDataProvider pollingDataProvider= (EventPollingDataProvider) SingletonServiceFactory.getBean(EventPollingDataProvider.class); | ||
PollingDao pollingDao = new PollingDao(pollingDataProvider, ds, 5,5, 100); | ||
|
||
|
||
@BeforeClass | ||
public static void setUp() { | ||
|
||
} | ||
|
||
@Test | ||
public void testDao() { | ||
List<PublishedEvent> result= pollingDao.findEventsToPublish(); | ||
assertTrue(result.size()>0); | ||
|
||
} | ||
|
||
@Test | ||
public void testDao2() { | ||
|
||
List<PublishedEvent> events = new ArrayList<>(); | ||
PublishedEvent event1 = new PublishedEvent(); | ||
event1.setId("111"); | ||
PublishedEvent event2 = new PublishedEvent(); | ||
event2.setId("222"); | ||
events.add(event1); | ||
events.add(event2); | ||
pollingDao.markEventsAsPublished(events); | ||
|
||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
eventuate-cdc-connector-polling/src/test/resources/config/service.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
singletons: | ||
- javax.sql.DataSource: | ||
- com.zaxxer.hikari.HikariDataSource: | ||
DriverClassName: org.h2.jdbcx.JdbcDataSource | ||
jdbcUrl: jdbc:h2:~/test | ||
username: sa | ||
password: sa | ||
- com.networknt.eventuate.cdc.polling.EventPollingDataProvider: | ||
- com.networknt.eventuate.cdc.polling.EventPollingDataProvider |
Oops, something went wrong.