Skip to content

proof of concept for message durability with small files (fit a batch request) #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Created by https://www.gitignore.io
analytics/pending

### Maven ###
target/
Expand Down Expand Up @@ -128,4 +129,4 @@ atlassian-ide-plugin.xml
.classpath
.project
.settings/
.factorypath
.factorypath
60 changes: 60 additions & 0 deletions ARQUITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
```mermaid

sequenceDiagram
box Data Consolidation
participant ConsolidationService
end

participant SegmentClient
box HTTP
participant QueueHttp
participant LooperHttp
participant SegmentAPI
end
box File
participant QueueFile
participant WriteFile
participant File
participant WatchFile
end

activate ConsolidationService
ConsolidationService->>+SegmentClient: enqueue
SegmentClient<<->>QueueHttp: offer
alt QueueHttp overflow
SegmentClient<<->>QueueFile: put
end
SegmentClient->>-ConsolidationService:
deactivate ConsolidationService

loop consume QueueHttp
LooperHttp->>QueueHttp:take
activate LooperHttp
end
LooperHttp->>SegmentAPI: batchUpload
note over LooperHttp,SegmentAPI: Batch
note over LooperHttp,SegmentAPI: CircuitBreaker and Retry
note over LooperHttp,SegmentAPI: HTTP requests submited to a pool
deactivate LooperHttp

alt retry exhausted or circuit open
note over LooperHttp: pool threads
LooperHttp->>QueueFile: put
end

loop consume QueueFile
WriteFile->>QueueFile:take
activate WriteFile
end
WriteFile->>File: write
note over WriteFile: Batch and save file
deactivate WriteFile

note over WatchFile: check last written
activate WatchFile
loop watch QueueFile
WatchFile->>File: read and remove
WatchFile->>QueueHttp: offer
end
deactivate WatchFile
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.segment.analytics.messages.Batch;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
Expand All @@ -11,4 +12,7 @@
public interface SegmentService {
@POST
Call<UploadResponse> upload(@Url HttpUrl uploadUrl, @Body Batch batch);

@POST
Call<UploadResponse> upload(@Url HttpUrl uploadUrl, @Body RequestBody batch);
}
42 changes: 39 additions & 3 deletions analytics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,21 @@
<artifactId>findbugs</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.segment.backo</groupId>
<artifactId>backo</artifactId>
<groupId>dev.failsafe</groupId>
<artifactId>failsafe</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>dev.failsafe</groupId>
<artifactId>failsafe-retrofit</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -67,7 +79,19 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -84,6 +108,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.file>
${project.basedir}/src/test/resources/logging.properties
</java.util.logging.config.file>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading