Skip to content

Commit

Permalink
#23 splitted the project in three maven modules: one core library wit…
Browse files Browse the repository at this point in the history
…hout any spring or third party tool dependency, one spring boot starter and one, that ties them all together
  • Loading branch information
BGehrels committed May 22, 2017
1 parent 34dba59 commit 4672a86
Show file tree
Hide file tree
Showing 51 changed files with 380 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.zalando.fahrschein.NakadiClient;
import org.zalando.nakadiproducer.eventlog.EventLogWriter;
import org.zalando.nakadiproducer.eventlog.impl.EventLogRepository;
import org.zalando.nakadiproducer.eventlog.impl.EventLogRepositoryImpl;
import org.zalando.nakadiproducer.eventlog.impl.EventLogWriterImpl;
import org.zalando.nakadiproducer.flowid.FlowIdComponent;
import org.zalando.nakadiproducer.flowid.NoopFlowIdComponent;
import org.zalando.nakadiproducer.flowid.TracerFlowIdComponent;
Expand All @@ -38,9 +43,13 @@
import org.zalando.nakadiproducer.snapshots.impl.SnapshotEventCreationMvcEndpoint;
import org.zalando.nakadiproducer.snapshots.impl.SnapshotEventProviderNotImplementedException;
import org.zalando.nakadiproducer.transmission.NakadiPublishingClient;
import org.zalando.nakadiproducer.transmission.impl.EventTransmissionService;
import org.zalando.nakadiproducer.transmission.impl.EventTransmitter;
import org.zalando.nakadiproducer.transmission.impl.FahrscheinNakadiPublishingClient;
import org.zalando.tracer.Tracer;

import com.fasterxml.jackson.databind.ObjectMapper;

@Configuration
@Slf4j
@ComponentScan
Expand Down Expand Up @@ -133,6 +142,31 @@ public SnapshotEventCreationMvcEndpoint snapshotEventCreationMvcEndpoint(Snapsho
return new SnapshotEventCreationMvcEndpoint(snapshotEventCreationEndpoint);
}

@Bean
public SnapshotCreationService snapshotCreationService(SnapshotEventProvider snapshotEventProvider, EventLogWriter eventLogWriter) {
return new SnapshotCreationService(snapshotEventProvider, eventLogWriter);
}

@Bean
public EventLogWriter eventLogWriter(EventLogRepository eventLogRepository, ObjectMapper objectMapper, FlowIdComponent flowIdComponent) {
return new EventLogWriterImpl(eventLogRepository, objectMapper, flowIdComponent);
}

@Bean
public EventLogRepository eventLogRepository(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
return new EventLogRepositoryImpl(namedParameterJdbcTemplate);
}

@Bean
public EventTransmitter eventTransmitter(EventTransmissionService eventTransmissionService) {
return new EventTransmitter(eventTransmissionService);
}

@Bean
public EventTransmissionService eventTransmissionService(EventLogRepository eventLogRepository, NakadiPublishingClient nakadiPublishingClient, ObjectMapper objectMapper) {
return new EventTransmissionService(eventLogRepository, nakadiPublishingClient, objectMapper);
}

@PostConstruct
public void migrateFlyway() {
Flyway flyway = new Flyway();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
import org.springframework.stereotype.Component;

@Component
public class EventLogRepository {
public class EventLogRepositoryImpl implements EventLogRepository {
private NamedParameterJdbcTemplate jdbcTemplate;

@Autowired
public EventLogRepository(NamedParameterJdbcTemplate jdbcTemplate) {
public EventLogRepositoryImpl(NamedParameterJdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}

@Override
public Collection<EventLog> findByLockedByAndLockedUntilGreaterThan(String lockedBy, Instant lockedUntil) {
Map<String, Object> namedParameterMap = new HashMap<>();
namedParameterMap.put("lockedBy", lockedBy);
Expand All @@ -34,6 +35,7 @@ public Collection<EventLog> findByLockedByAndLockedUntilGreaterThan(String locke
);
}

@Override
public void lockSomeMessages(String lockId, Instant now, Instant lockExpires) {
Map<String, Object> namedParameterMap = new HashMap<>();
namedParameterMap.put("lockId", lockId);
Expand All @@ -45,6 +47,7 @@ public void lockSomeMessages(String lockId, Instant now, Instant lockExpires) {
);
}

@Override
public void delete(EventLog eventLog) {
Map<String, Object> namedParameterMap = new HashMap<>();
namedParameterMap.put("id", eventLog.getId());
Expand All @@ -54,6 +57,7 @@ public void delete(EventLog eventLog) {
);
}

@Override
public void persist(EventLog eventLog) {
Timestamp now = toSqlTimestamp(Instant.now());
MapSqlParameterSource namedParameterMap = new MapSqlParameterSource();
Expand Down Expand Up @@ -85,10 +89,12 @@ private Timestamp toSqlTimestamp(Instant now) {
return Timestamp.from(now);
}

@Override
public void deleteAll() {
jdbcTemplate.update("DELETE from nakadi_events.event_log", new HashMap<>());
}

@Override
public EventLog findOne(Integer id) {
Map<String, Object> namedParameterMap = new HashMap<>();
namedParameterMap.put("id", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class EventLogRepositoryIT extends BaseMockedExternalCommunicationIT {

@Autowired
private EventLogRepository eventLogRepository;
private EventLogRepositoryImpl eventLogRepository;

private static final String WAREHOUSE_EVENT_BODY_DATA =
("{'self':'http://WAREHOUSE_DOMAIN',"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.zalando.nakadiproducer;
package org.zalando.nakadiproducer.flowid;

import static org.junit.Assert.assertThat;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.zalando.nakadiproducer.util;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@ToString
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class MockPayload {
private Integer id;

private String code;

@Builder.Default
private boolean isActive = true;

private SubClass more;

private List<SubListItem> items;

@Builder(toBuilder = true)
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public static class SubClass {
private String info;
}

@Builder(toBuilder = true)
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public static class SubListItem {
private String detail;
}
}
File renamed without changes.
177 changes: 177 additions & 0 deletions nakadi-producer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<prerequisites>
<maven>3.2</maven>
</prerequisites>

<parent>
<groupId>org.zalando</groupId>
<artifactId>nakadi-producer-reactor</artifactId>
<version>3.1.0-SNAPSHOT</version>
</parent>

<artifactId>nakadi-producer</artifactId>
<groupId>org.zalando</groupId>
<version>3.1.0-SNAPSHOT</version>
<name>Nakadi Event Producer</name>
<description>Reliable transactional Nakadi event producer</description>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
<zalando-swagger-codegen-maven-plugin.version>0.4.24</zalando-swagger-codegen-maven-plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.zalando</groupId>
<artifactId>fahrschein</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!--
JPAs @Transactional is annotated with @InterceptorBinding. Javadoc generation would therefore fail if it is
not on the build classpath.
-->
<dependency>
<groupId>javax.interceptor</groupId>
<artifactId>javax.interceptor-api</artifactId>
<version>1.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.8.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>

<licenses>
<license>
<name>MIT</name>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.zalando.nakadiproducer.eventlog.impl;

import java.time.Instant;
import java.util.Collection;

public interface EventLogRepository {
Collection<EventLog> findByLockedByAndLockedUntilGreaterThan(String lockedBy, Instant lockedUntil);

void lockSomeMessages(String lockId, Instant now, Instant lockExpires);

void delete(EventLog eventLog);

void persist(EventLog eventLog);

void deleteAll();

EventLog findOne(Integer id);
}
Loading

0 comments on commit 4672a86

Please sign in to comment.