-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
fj-service-helper-demo/src/main/java/org/fugerit/java/sh/demo/redis/ServiceMapRedisRest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.fugerit.java.sh.demo.redis; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.microprofile.openapi.annotations.Operation; | ||
import org.eclipse.microprofile.openapi.annotations.media.Content; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
import org.fugerit.java.dsb.attributes.SimpleServiceMap; | ||
import org.fugerit.java.emp.sm.service.ServiceMessage; | ||
import org.fugerit.java.emp.sm.service.ServiceResponse; | ||
|
||
import io.vertx.core.cli.annotations.Description; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@ApplicationScoped | ||
@Path("/service/redis") | ||
@Description("Demo service for Service Map Quarkus Redis") | ||
public class ServiceMapRedisRest { | ||
|
||
@Inject | ||
private SimpleServiceMap serviceMap; | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@APIResponse(responseCode = "200", description = "Operation OK!", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON, | ||
schema = @Schema(implementation = ServiceResponse.class))) | ||
@Path("/set/{key}/{value}") | ||
@Operation(operationId = "redis set ok", summary = "set the key/value pair from path pararmeters.") | ||
public Response redisSet( @PathParam("key") String key, @PathParam("value") String value ) { | ||
ServiceResponse sr = new ServiceResponse(); | ||
serviceMap.set(key, value); | ||
sr.setSuccess(Arrays.asList(new ServiceMessage("200002", ServiceMessage.SEVERITY_SUCCESS, String.format( "Set OK key : %s, value : %s" , key, value ) ))); | ||
return Response.ok().entity(sr).build(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@APIResponse(responseCode = "200", description = "Operation OK!", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON, | ||
schema = @Schema(implementation = ServiceResponse.class))) | ||
@Path("/get/{key}") | ||
@Operation(operationId = "redis get ok", summary = "get the value from key path pararmeter.") | ||
public Response redisGet( @PathParam("key") String key ) { | ||
ServiceResponse sr = new ServiceResponse(); | ||
String value = serviceMap.get(key); | ||
sr.setSuccess(Arrays.asList(new ServiceMessage("200003", ServiceMessage.SEVERITY_SUCCESS, String.format( "Get OK key : %s, value : %s" , key, value ) ))); | ||
return Response.ok().entity(sr).build(); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
fj-service-helper-demo/src/main/java/org/fugerit/java/sh/demo/redis/SessionRedis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.fugerit.java.sh.demo.redis; | ||
|
||
import org.fugerit.java.dsb.attributes.SimpleServiceMap; | ||
import org.fugerit.java.dsb.attributes.redis.SimpleServiceMapRedisDefault; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Default; | ||
|
||
@ApplicationScoped | ||
@Default | ||
public class SessionRedis extends SimpleServiceMapRedisDefault implements SimpleServiceMap { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ | |
enabled: false | ||
swagger-ui: | ||
always-include: true | ||
redis: | ||
hosts: redis://localhost:6379 | ||
devservices: | ||
enabled: true |
27 changes: 27 additions & 0 deletions
27
...elper-demo/src/test/java/test/org/fugerit/java/sh/demo/redis/TestServiceMapRedisRest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package test.org.fugerit.java.sh.demo.redis; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@QuarkusTest | ||
class TestServiceMapRedisRest { | ||
|
||
@Test | ||
void testRedisSetGetOK() { | ||
given() | ||
.when() | ||
.get( "/service/redis/set/myKey/myValue" ) | ||
.then() | ||
.statusCode( Response.Status.OK.getStatusCode() ); | ||
given() | ||
.when() | ||
.get( "/service/redis/get/myKey" ) | ||
.then() | ||
.statusCode( Response.Status.OK.getStatusCode() ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...map/src/main/java/org/fugerit/java/dsb/attributes/redis/SimpleServiceMapRedisDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.fugerit.java.dsb.attributes.redis; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.fugerit.java.dsb.attributes.SimpleServiceMap; | ||
|
||
import io.quarkus.redis.datasource.RedisDataSource; | ||
import io.quarkus.redis.datasource.value.ValueCommands; | ||
import jakarta.inject.Inject; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class SimpleServiceMapRedisDefault implements SimpleServiceMap { | ||
|
||
@ConfigProperty( name = "cache.ttl-ms", defaultValue = "600000" ) // 10 minutes | ||
private long ttl; | ||
|
||
@Inject | ||
private RedisDataSource ds; | ||
|
||
private ValueCommands<String, String> com() { | ||
return this.ds.value( String.class ); | ||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
log.debug( "get key:{}", key ); | ||
return this.com().get(key); | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
log.debug( "set key:{}, ttl:{}", key, this.ttl ); | ||
this.com().psetex(key, this.ttl, value); | ||
} | ||
|
||
@Override | ||
public void remove(String key) { | ||
log.warn( "remove method not implemented, key:{}", key ); | ||
} | ||
|
||
} |