Skip to content

Commit

Permalink
Merge pull request #33 from zalando-incubator/fix-docs
Browse files Browse the repository at this point in the history
#23 Support using the library in a non-springboot project
  • Loading branch information
ePaul authored May 24, 2017
2 parents 2f9ce03 + af6694f commit 737a6b7
Show file tree
Hide file tree
Showing 54 changed files with 598 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk:
- oraclejdk8
install: ./mvnw dependency:resolve
install: ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -Dgpg.skip=true -B -V
script: ./mvnw verify -Dgpg.skip=true
190 changes: 190 additions & 0 deletions nakadi-producer-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?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.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>

<artifactId>nakadi-producer-spring-boot-starter</artifactId>
<groupId>org.zalando</groupId>
<version>3.1.0-SNAPSHOT</version>
<name>Nakadi Event Producer: Spring Boot Starter</name>
<description>Spring Boot Auto Configuration for 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>org.zalando</groupId>
<artifactId>nakadi-producer</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.zalando</groupId>
<artifactId>tracer-core</artifactId>
<version>0.11.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.zalando.stups</groupId>
<artifactId>tokens</artifactId>
<version>0.11.0-beta-2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>0.7.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>postgresql</artifactId>
<groupId>postgresql</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</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,26 @@
package org.zalando.nakadiproducer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.zalando.nakadiproducer.transmission.impl.EventTransmitter;

@Component
public class EventTransmissionScheduler {
private final EventTransmitter eventTransmitter;
private final boolean scheduledTransmissionEnabled;

@Autowired
public EventTransmissionScheduler(EventTransmitter eventTransmitter, @Value("${nakadi-producer.scheduled-transmission-enabled:true}") boolean scheduledTransmissionEnabled) {
this.eventTransmitter = eventTransmitter;
this.scheduledTransmissionEnabled = scheduledTransmissionEnabled;
}

@Scheduled(fixedDelayString = "${nakadi-producer.transmission-polling-delay:1000}")
protected void sendEventsIfSchedulingEnabled() {
if (scheduledTransmissionEnabled) {
eventTransmitter.sendEvents();
}
}
}
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,32 @@ 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
Loading

0 comments on commit 737a6b7

Please sign in to comment.