Skip to content

Commit

Permalink
Added Redis implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
aseovic committed Jan 30, 2020
1 parent b4ef4ae commit 769eb6c
Show file tree
Hide file tree
Showing 11 changed files with 440 additions and 7 deletions.
6 changes: 3 additions & 3 deletions catalog-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ $ docker run -p 7001:7001 helidonsockshop/catalog-core
```

Once the container is up and running, you should be able to access [service API](../README.md#api)
by navigating to http://localhost:7001/catalog/.
by navigating to http://localhost:7001/catalogue/.

As a basic test, you should be able to perform an HTTP GET against `/catalog` endpoint:
As a basic test, you should be able to perform an HTTP GET against `/catalogue/size` endpoint:

```bash
$ curl http://localhost:7001/catalog/size
$ curl http://localhost:7001/catalogue/size
```
which should return JSON response
```json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void init() {
/**
* Load test data into this repository.
*/
protected CatalogRepository loadData() {
public CatalogRepository loadData() {
if (socks.isEmpty()) {
loadSocksFromJson(Sock.class)
.forEach(sock -> socks.put(sock.getId(), sock));
Expand Down
6 changes: 3 additions & 3 deletions catalog-mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ $ docker run --network sockshop -p 7001:7001 helidonsockshop/catalog-mongo
```

Once the container is up and running, you should be able to access [service API](../README.md#api)
by navigating to http://localhost:7001/catalog/.
by navigating to http://localhost:7001/catalogue/.

As a basic test, you should be able to perform an HTTP GET against `/catalog/{customerId}` endpoint:
As a basic test, you should be able to perform an HTTP GET against `/catalogue/size` endpoint:

```bash
$ curl http://localhost:7001/catalog/size
$ curl http://localhost:7001/catalogue/size
```
which should return JSON response
```json
Expand Down
55 changes: 55 additions & 0 deletions catalog-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# catalog-redis

This module implements [Redis backend](./src/main/java/io/helidon/examples/sockshop/catalog/redis/RedisCatalogRepository.java)
for the [Product Catalog Service](../README.md) using Redisson client.

## Building the Service

See [main documentation page](../README.md#building-the-service) for instructions.

## Running the Service

This implementation is slightly more complex to run, because it requires a Redis instance
to use as a data store.

First you will need to create a Docker network that will be used by both Redis and the service
containers, if you haven't done that already:

```bash
$ docker network create sockshop
```

Then you can run Redis container, but you need to assign it to the `sockshop` network
created above, and give it a name that the service container expects (`catalog-db` in this case):

```bash
$ docker run --rm --name catalog-db --network sockshop redis:5.0.7
```
> **Note:** The `--rm` flag above ensures that the container is removed automatically after it is
> stopped. This allows you to re-run the command above without having to remove the `catalog-db`
> container manually between runs.
Finally, you can start the service container in the same network:

```bash
$ docker run --network sockshop -p 7001:7001 helidonsockshop/catalog-redis
```

Once the container is up and running, you should be able to access [service API](../README.md#api)
by navigating to http://localhost:7001/catalogue/.

As a basic test, you should be able to perform an HTTP GET against `/catalogue/size` endpoint:

```bash
$ curl http://localhost:7001/catalogue/size
```
which should return JSON response
```json
{
"size": 9
}
```

## License

Apache License 2.0
230 changes: 230 additions & 0 deletions catalog-redis/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<?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>

<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>1.4.1</version>
<relativePath/>
</parent>

<groupId>io.helidon.examples.sockshop</groupId>
<artifactId>catalog-redis</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<mainClass>io.helidon.microprofile.server.Main</mainClass>
<docker.repo>helidonsockshop</docker.repo>
<docker.version>${project.version}</docker.version>
<jib.goal>dockerBuild</jib.goal>

<!-- dependencies -->
<version.lib.lombok>1.18.10</version.lib.lombok>
<version.lib.redisson>3.12.0</version.lib.redisson>
<version.lib.junit>5.5.0</version.lib.junit>
<version.lib.hamcrest>1.3</version.lib.hamcrest>
<version.lib.rest-assured>4.2.0</version.lib.rest-assured>

<version.plugin.surefire>2.22.1</version.plugin.surefire>
<version.plugin.failsafe>2.22.1</version.plugin.failsafe>
<version.plugin.surefire.provider.junit>1.3.2</version.plugin.surefire.provider.junit>
</properties>

<dependencies>
<!-- Project dependencies -->
<dependency>
<groupId>io.helidon.examples.sockshop</groupId>
<artifactId>catalog-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.examples.sockshop</groupId>
<artifactId>catalog-core</artifactId>
<classifier>tests</classifier>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<!-- Helidon dependencies-->
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>

<!-- Redis dependencies -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${version.lib.redisson}</version>
</dependency>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${version.lib.lombok}</version>
<scope>provided</scope>
</dependency>

<!--JPA -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- test dependencies-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.lib.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.lib.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${version.lib.hamcrest}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${version.lib.rest-assured}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.1</version>
<executions>
<execution>
<id>prepare-it-database</id>
<goals>
<goal>start</goal>
</goals>
<configuration>
<images>
<image>
<name>redis:5.0.7</name>
<alias>catalog-db</alias>
<run>
<ports>
<port>db.port:6379</port>
</ports>
<wait>
<log>(?s)Ready to accept connections
</log>
<time>10000</time>
</wait>
</run>
</image>
</images>
</configuration>
</execution>
<execution>
<id>remove-it-database</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<db.host>localhost</db.host>
<db.port>${db.port}</db.port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<to>
<image>${docker.repo}/${project.artifactId}</image>
<tags>
<tag>${docker.version}</tag>
</tags>
</to>
<container>
<!-- good defaults intended for containers -->
<jvmFlags>
<jmxFlag>-server</jmxFlag>
<jmxFlag>-Djava.awt.headless=true</jmxFlag>
<jmxFlag>-XX:+UnlockExperimentalVMOptions</jmxFlag>
<jmxFlag>-XX:+UseCGroupMemoryLimitForHeap</jmxFlag>
<jmxFlag>-XX:InitialRAMFraction=2</jmxFlag>
<jmxFlag>-XX:MinRAMFraction=2</jmxFlag>
<jmxFlag>-XX:MaxRAMFraction=2</jmxFlag>
<jmxFlag>-XX:+UseG1GC</jmxFlag>
</jvmFlags>
<mainClass>${mainClass}</mainClass>
<ports>
<port>7001</port>
</ports>
</container>
<containerizingMode>packaged</containerizingMode>
</configuration>
<executions>
<execution>
<goals>
<goal>${jib.goal}</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.helidon.examples.sockshop.carts.redis;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Specializes;
import javax.inject.Inject;

import io.helidon.examples.sockshop.catalog.DefaultCatalogRepository;
import io.helidon.examples.sockshop.catalog.Sock;

import org.redisson.api.RMap;

/**
* An implementation of {@link io.helidon.examples.sockshop.catalog.CatalogRepository}
* that that uses Redis (via Redisson) as a backend data store.
*/
@ApplicationScoped
@Specializes
public class RedisCatalogRepository extends DefaultCatalogRepository {
@Inject
public RedisCatalogRepository(RMap<String, Sock> socks) {
super(socks);
}
}
Loading

0 comments on commit 769eb6c

Please sign in to comment.