Skip to content

What's new in Infinispan Client Extension - Quarkus Insights Demo 23/01/2023

License

Notifications You must be signed in to change notification settings

infinispan-demos/quarkus-insights-demo

Repository files navigation

Quarkus Insights 23-01-23 Demo Project

Slides

Quarkus Insights #115 - What's new in Infinispan.pdf

Based repositories

This project is based on the following repositories:

Demo Steps

Dev services

  1. Start Quarkus with Docker running
./mvnw quarkus:dev
  1. Open Dev UI (d), open the Infinispan Console
  2. Inject a cache in Greeting Resource
    @Inject
    @Remote("greetings")
    RemoteCache<String, String> greetingsCache;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        greetingsCache.put("123", "Hello Quarkus Insights");
        return "Hello Quarkus";
    }
  1. Command line
http localhost:8080/hello 
  1. Adding fixed port
quarkus.infinispan-client.devservices.port=11223

Health Check

  1. Show that we have the Health Extension
  2. In the DEV UI access to the Health UI and show the Readiness Endpoint available
  3. Default enabled, can be disabled with the following property
quarkus.infinispan-client.health.enabled=false

Create Caches with configuration

  1. Change the service to use a put new Developer
@Inject
@Remote("greetings")
RemoteCache<String, Developer> greetingsCache;

greetingsCache.put("hcummins", new Developer("Holly", "Cummins", "Quarkus"));
  1. Test command line again and check marshalling error
http localhost:8080/hello 
  1. Open the model and annotate
public class Developer {
   private String firstname;
   private String lastName;
   private String project;

   @ProtoFactory
   public Developer(String firstname, String lastName, String project) {
      this.firstname = firstname;
      this.lastName = lastName;
      this.project = project;
   }

   @ProtoField(value = 1)
   public String getFirstname() {
      return firstname;
   }

   @ProtoField(value = 2)
   public String getLastName() {
      return lastName;
   }

   @ProtoField(value = 3)
   public String getProject() {
      return project;
   }
}
  1. Create the schema
@AutoProtoSchemaBuilder(includeClasses = { Developer.class },
      schemaFileName = "developers-schema.proto",
      schemaPackageName = "insights")
interface DevelopersSchema extends GeneratedSchema {

}
  1. Run again the command line and go to the console
http localhost:8080/hello 
  1. Explain that we want to create a new cache that will hold max 3 entries.

  2. Configure with the console a bounded cache and create developers.json

  3. Configure in the properties

quarkus.infinispan-client.cache.developers.configuration-uri=developers.json
  1. Explain the configuration of the near caching in the properties
quarkus.infinispan-client.cache.developers.near-cache-max-entries=20
  1. Disable upload schema disable
quarkus.infinispan-client.use-schema-registration=false

Use caching annotations

  1. Get a developer
http  localhost:8080/hello/wburns
  1. Check service call all the time
http  localhost:8080/hello/wburns
  1. Add @CacheResult and check calls and the console
   @CacheResult(cacheName = "developers")
  1. Remove the developer and check the console is still there
http delete localhost:8080/hello/wburns 
http  localhost:8080/hello/wburns  
  1. Use @CacheInvalidate, retry and check the console
 @CacheInvalidate(cacheName = "developers")
http delete localhost:8080/hello/wburns 
http  localhost:8080/hello/wburns  
  1. Use @CacheInvalidateAll, to remove all and check the console

Search and Indexing

  1. Add indexing model:
  • create the package org.infinispan.search
  • add java classes: Author, Book, Review, BooksSchema
  1. Build and star the dev mode
./mvnw compile quarkus:dev
  1. Show the schemas on Infinispan console

  2. Highlight the fact that in production you should set:

quarkus.infinispan-client.use-schema-registration=false
  1. Create the cache books (startupMode => Replicated, None, local-indexed, indexed entities => insights.book)
  • download the file (yaml)
  1. Copy file books.yaml => main/resources/
  • add to application.properties
quarkus.infinispan-client.cache.books.configuration-uri=books.yaml
  1. Copy ModelGenerator to org.infinispan.search.generator

    • Copy BookResource to org.infinispan
    • Compile and run dev mode
    ./mvnw compile quarkus:dev
    
    • Play with queries
    http PUT localhost:8080/books
    http localhost:8080/books/description/java
    
    • Show the statistics
    • Show you can do the same query from console from insights.book b where b.description : 'concurrency'
  2. Test showcases

  • Copy SearchTest to org.infinispan.search
  • Show the test cases

Tracing to main

  1. Run Jaeger container
docker run --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4317:4317 \
  --rm \
  jaegertracing/all-in-one:1.36
  1. Find the bridge network address ip for it:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' jaeger
  1. In application.properties replace the:
quarkus.opentelemetry.enabled=false

with:

quarkus.infinispan-client.devservices.tracing.enabled=true
# Replace 172.17.0.2 with the output of docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' jaeger
quarkus.infinispan-client.devservices.tracing.exporter.otlp.endpoint=http://172.17.0.2:4317

quarkus.opentelemetry.tracer.exporter.otlp.endpoint=http://localhost:4317
  1. Add methods to the QuarkusInsightsResource endpoint
@PUT
@Path("async/{calls}")
@Produces(MediaType.TEXT_PLAIN)
@WithSpan(value = "wait-for-async", kind = SpanKind.CLIENT)
public String putAsync(@PathParam("calls") Integer calls) {
  CompletableFuture[] promises = IntStream.range(0, calls).boxed()
        .map(value -> greetingsCache.putAsync(value.toString(), Character.toString('A' + value)))
        .toList().toArray(new CompletableFuture[0]);

  CompletableFuture.allOf(promises).join();

  return "Executed " + calls + " calls.";
}

@PUT
@Path("bulk/{calls}")
@Produces(MediaType.TEXT_PLAIN)
@WithSpan(value = "wait-for-putAll", kind = SpanKind.CLIENT)
public String putAll(@PathParam("calls") Integer calls) {
  greetingsCache.putAll(IntStream.range(0, calls).boxed()
        .collect(Collectors.toMap(value -> value.toString(), value -> Character.toString('A' + value))));

  return "Executed " + calls + " calls.";
}
  1. Build and run the dev mode:
./mvnw compile quarkus:dev
  1. Curl the endpoint
http PUT localhost:8080/hello/async/10
http PUT localhost:8080/hello/bulk/10

About

What's new in Infinispan Client Extension - Quarkus Insights Demo 23/01/2023

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published