Search in sources :

Example 1 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class EventTableChangesToAggregateTopicRelay method handleEvent.

protected void handleEvent(EventToPublish eventToPublish) {
    PublishedEvent pe = new PublishedEvent(eventToPublish.getEventId(), eventToPublish.getEntityId(), eventToPublish.getEntityType(), eventToPublish.getEventData(), eventToPublish.getEventType(), null, eventToPublish.getMetadataOptional());
    String aggregateTopic = AggregateTopicMapping.aggregateTypeToTopic(pe.getEntityType());
    String json = toJson(pe);
    if (logger.isInfoEnabled())
        logger.debug("Publishing triggeringEvent={}, event={}", eventToPublish.getTriggeringEvent(), json);
    try {
        producer.send(aggregateTopic, eventToPublish.getEntityId(), json).get(10, TimeUnit.SECONDS);
    } catch (RuntimeException e) {
        logger.error("error publishing to " + aggregateTopic, e);
        throw e;
    } catch (Throwable e) {
        logger.error("error publishing to " + aggregateTopic, e);
        throw new RuntimeException(e);
    }
}
Also used : PublishedEvent(io.eventuate.local.common.PublishedEvent)

Example 2 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class AbstractDuplicatePublishingDetectorTest method floodTopic.

private void floodTopic(Producer<String, String> producer, String binlogFilename, String topicName) {
    for (int i = 0; i < 10; i++) {
        PublishedEvent publishedEvent = new PublishedEvent();
        publishedEvent.setEntityId(UUID.randomUUID().toString());
        publishedEvent.setBinlogFileOffset(new BinlogFileOffset(binlogFilename, (long) i));
        String json = JSonMapper.toJson(publishedEvent);
        producer.send(new ProducerRecord<>(topicName, publishedEvent.getEntityId(), json));
    }
}
Also used : BinlogFileOffset(io.eventuate.local.common.BinlogFileOffset) PublishedEvent(io.eventuate.local.common.PublishedEvent)

Example 3 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class AbstractDuplicatePublishingDetectorTest method sendOldPublishedEvent.

private void sendOldPublishedEvent(Producer<String, String> producer, String topicName) {
    for (int i = 0; i < 10; i++) {
        PublishedEvent publishedEvent = new PublishedEvent();
        publishedEvent.setEntityId(UUID.randomUUID().toString());
        String json = JSonMapper.toJson(publishedEvent);
        producer.send(new ProducerRecord<>(topicName, publishedEvent.getEntityId(), json));
    }
}
Also used : PublishedEvent(io.eventuate.local.common.PublishedEvent)

Example 4 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class MySQLMigrationTest method test.

@Test
public void test() throws Exception {
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    CdcProcessor<PublishedEvent> cdcProcessor = createMySQLCdcProcessor();
    cdcProcessor.start(publishedEvent -> {
        publishedEvents.add(publishedEvent);
        databaseOffsetKafkaStore.save(publishedEvent.getBinlogFileOffset());
    });
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    List<EventTypeAndData> events = Collections.singletonList(new EventTypeAndData("TestEvent_MIGRATION", "{}", Optional.empty()));
    EntityIdVersionAndEventIds entityIdVersionAndEventIds = localAggregateCrud.save("TestAggregate_MIGRATION", events, Optional.empty());
    PublishedEvent publishedEvent;
    while ((publishedEvent = publishedEvents.poll(10, TimeUnit.SECONDS)) != null) {
        if ("TestEvent_MIGRATION".equals(publishedEvent.getEventType())) {
            break;
        }
    }
    Assert.assertNotNull(publishedEvent);
    Assert.assertEquals(entityIdVersionAndEventIds.getEntityVersion().asString(), publishedEvent.getId());
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) EventuateLocalAggregateCrud(io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud) EventTypeAndData(io.eventuate.javaclient.commonimpl.EventTypeAndData) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test) AbstractCdcTest(io.eventuate.local.test.util.AbstractCdcTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PublishedEvent

use of io.eventuate.local.common.PublishedEvent in project eventuate-local by eventuate-local.

the class AbstractPostgresWalCdcIntegrationTest method shouldGetEvents.

@Test
public void shouldGetEvents() throws InterruptedException {
    PostgresWalClient<PublishedEvent> postgresWalClient = new PostgresWalClient<>(postgresWalMessageParser, dataSourceURL, dbUserName, dbPassword, eventuateConfigurationProperties.getBinlogConnectionTimeoutInMilliseconds(), eventuateConfigurationProperties.getMaxAttemptsForBinlogConnection(), eventuateConfigurationProperties.getPostgresWalIntervalInMilliseconds(), eventuateConfigurationProperties.getPostgresReplicationStatusIntervalInMilliseconds(), eventuateConfigurationProperties.getPostgresReplicationSlotName());
    EventuateLocalAggregateCrud localAggregateCrud = new EventuateLocalAggregateCrud(eventuateJdbcAccess);
    BlockingQueue<PublishedEvent> publishedEvents = new LinkedBlockingDeque<>();
    postgresWalClient.start(Optional.empty(), publishedEvents::add);
    String accountCreatedEventData = generateAccountCreatedEvent();
    EntityIdVersionAndEventIds saveResult = saveEvent(localAggregateCrud, accountCreatedEventData);
    String accountDebitedEventData = generateAccountDebitedEvent();
    EntityIdVersionAndEventIds updateResult = updateEvent(saveResult.getEntityId(), saveResult.getEntityVersion(), localAggregateCrud, accountDebitedEventData);
    // Wait for 10 seconds
    LocalDateTime deadline = LocalDateTime.now().plusSeconds(10);
    waitForEvent(publishedEvents, saveResult.getEntityVersion(), deadline, accountCreatedEventData);
    waitForEvent(publishedEvents, updateResult.getEntityVersion(), deadline, accountDebitedEventData);
    postgresWalClient.stop();
}
Also used : EntityIdVersionAndEventIds(io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds) LocalDateTime(java.time.LocalDateTime) EventuateLocalAggregateCrud(io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) PublishedEvent(io.eventuate.local.common.PublishedEvent) Test(org.junit.Test) AbstractCdcTest(io.eventuate.local.test.util.AbstractCdcTest)

Aggregations

PublishedEvent (io.eventuate.local.common.PublishedEvent)11 EntityIdVersionAndEventIds (io.eventuate.javaclient.commonimpl.EntityIdVersionAndEventIds)6 Test (org.junit.Test)6 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)5 EventuateLocalAggregateCrud (io.eventuate.local.java.jdbckafkastore.EventuateLocalAggregateCrud)3 AbstractCdcTest (io.eventuate.local.test.util.AbstractCdcTest)3 LocalDateTime (java.time.LocalDateTime)2 EventTypeAndData (io.eventuate.javaclient.commonimpl.EventTypeAndData)1 BinlogFileOffset (io.eventuate.local.common.BinlogFileOffset)1 JdbcUrl (io.eventuate.local.common.JdbcUrl)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1