Skip to content

Commit

Permalink
Added Docker Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiej.zylinski committed Jun 6, 2024
1 parent a974156 commit 407eebb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 77 deletions.
24 changes: 24 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.9'

volumes:
nats-storage:
driver: local

services:
nats:
image: nats:2.10.7
command: [ "--jetstream", "-m", "8222" ]
deploy:
resources:
limits:
memory: 2g
reservations:
memory: 2g
volumes:
- nats-storage:/data
expose:
- "4222"
- "8222"
ports:
- "4222:4222"
- "8222:8222"
49 changes: 8 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
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>

<groupId>com.softwaremill</groupId>
<artifactId>OtterJet</artifactId>
<groupId>com.softwaremill.otter</groupId>
<artifactId>jet</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<packaging>jar</packaging>

<name>Visualization of messages from a NATS JetStream server</name>

Expand All @@ -16,7 +16,6 @@
<maven.compiler.target>17</maven.compiler.target>
<spotless.plugin.version>2.41.1</spotless.plugin.version>
<testcontainers.version>1.19.3</testcontainers.version>
<junit.version>5.10.1</junit.version>
<spring-boot.version>3.2.0</spring-boot.version>
<spring-cloud.version>2023.0.0</spring-cloud.version>
</properties>
Expand Down Expand Up @@ -44,13 +43,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>

</dependencyManagement>
Expand Down Expand Up @@ -107,11 +99,6 @@
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.ozark</groupId>
<artifactId>ozark</artifactId>
<version>1.0.0-m02</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -144,35 +131,20 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -185,11 +157,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
58 changes: 28 additions & 30 deletions src/main/java/otterjet/MsgsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
Expand All @@ -12,37 +13,34 @@
@Controller
public class MsgsController {

private static final String TEMPLATE_NAME = "msgs-page";
private static final Logger LOG = LoggerFactory.getLogger(MsgsController.class);
private static final String TEMPLATE_NAME = "msgs-page";
private static final Logger LOG = LoggerFactory.getLogger(MsgsController.class);

private final ReaderService readerService;
private String subjectFilter;
private String typeFilter;
private String bodyContentFilter;
private final ReaderService readerService;

public MsgsController(ReaderService readerService) {
this.readerService = readerService;
}
public MsgsController(ReaderService readerService) {
this.readerService = readerService;
}

@GetMapping("/msgs")
public String page(
@RequestParam(value = "subject", required = false) String subject,
@RequestParam(value = "type", required = false) String type,
@RequestParam(value = "bodyContent", required = false) String bodyContent,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "10") int size,
Model model) {
this.subjectFilter = Optional.ofNullable(subject).orElse("");
this.typeFilter = Optional.ofNullable(type).orElse("");
this.bodyContentFilter = Optional.ofNullable(bodyContent).orElse("");
List<ReadMessage> filteredMessages = readerService.filter(subjectFilter, typeFilter, page, size, bodyContentFilter);
LOG.info("amount of read messages: " + filteredMessages.size());
model.addAttribute("messages", filteredMessages);
model.addAttribute("subject", subjectFilter);
model.addAttribute("type", typeFilter);
model.addAttribute("bodyContent", bodyContentFilter);
model.addAttribute("page", page);
model.addAttribute("size", size);
return TEMPLATE_NAME;
}
@GetMapping("/msgs")
public String page(
@RequestParam(value = "subject", required = false) String subject,
@RequestParam(value = "type", required = false) String type,
@RequestParam(value = "bodyContent", required = false) String bodyContent,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "10") int size,
Model model) {
String subjectFilter = Optional.ofNullable(subject).orElse("");
String typeFilter = Optional.ofNullable(type).orElse("");
String bodyContentFilter = Optional.ofNullable(bodyContent).orElse("");
List<ReadMessage> filteredMessages = readerService.filter(subjectFilter, typeFilter, page, size, bodyContentFilter);
LOG.info("amount of read messages: " + filteredMessages.size());
model.addAttribute("messages", filteredMessages);
model.addAttribute("subject", subjectFilter);
model.addAttribute("type", typeFilter);
model.addAttribute("bodyContent", bodyContentFilter);
model.addAttribute("page", page);
model.addAttribute("size", size);
return TEMPLATE_NAME;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package otterjet.monitoring;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;

interface NatsMonitoringApiClient {
@RequestMapping(method = RequestMethod.GET, value = "/jsz?streams=true&config=true")
@GetMapping("/jsz?streams=true&config=true")
JetStreamMonitoringResponse getJetStreamMonitoringData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class NatsMonitoringAutoConfiguration {

@Configuration
@ConditionalOnExpression("'${nats.server.monitoring.port:}' != ''") // monitoring configured
@ConditionalOnExpression("'${nats.server.monitoring.port:}' != ''")
static class NatsMonitoringEnabledConfiguration {

@Bean
Expand Down Expand Up @@ -48,7 +48,7 @@ private static String createNatsMonitoringUrl(
}

@Configuration
@ConditionalOnExpression("'${nats.server.monitoring.port:}' == ''") // monitoring not configured
@ConditionalOnExpression("'${nats.server.monitoring.port:}' == ''")
@AutoConfigureAfter(NatsMonitoringEnabledConfiguration.class)
static class NatsMonitoringDisabledConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public DeserializedMessage deserializeMessage(ByteBuffer buffer) {
final var descriptors =
descs.stream()
.flatMap(desc -> desc.getMessageTypes().stream())
.collect(Collectors.toList());
.toList();
final var messageDescriptor =
descriptors.stream()
.filter(desc -> messageTypeName.equals(desc.getName()) || messageTypeName.equals(desc.getFullName()))
Expand Down

0 comments on commit 407eebb

Please sign in to comment.