Quarkus Insights #115 - What's new in Infinispan.pdf
This project is based on the following repositories:
- Start Quarkus with Docker running
./mvnw quarkus:dev
- Open Dev UI (d), open the Infinispan Console
- 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";
}
- Command line
http localhost:8080/hello
- Adding fixed port
quarkus.infinispan-client.devservices.port=11223
- Show that we have the Health Extension
- In the DEV UI access to the Health UI and show the Readiness Endpoint available
- Default enabled, can be disabled with the following property
quarkus.infinispan-client.health.enabled=false
- Change the service to use a put new Developer
@Inject
@Remote("greetings")
RemoteCache<String, Developer> greetingsCache;
greetingsCache.put("hcummins", new Developer("Holly", "Cummins", "Quarkus"));
- Test command line again and check marshalling error
http localhost:8080/hello
- 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;
}
}
- Create the schema
@AutoProtoSchemaBuilder(includeClasses = { Developer.class },
schemaFileName = "developers-schema.proto",
schemaPackageName = "insights")
interface DevelopersSchema extends GeneratedSchema {
}
- Run again the command line and go to the console
http localhost:8080/hello
-
Explain that we want to create a new cache that will hold max 3 entries.
-
Configure with the console a bounded cache and create
developers.json
-
Configure in the properties
quarkus.infinispan-client.cache.developers.configuration-uri=developers.json
- Explain the configuration of the near caching in the properties
quarkus.infinispan-client.cache.developers.near-cache-max-entries=20
- Disable upload schema disable
quarkus.infinispan-client.use-schema-registration=false
- Get a developer
http localhost:8080/hello/wburns
- Check service call all the time
http localhost:8080/hello/wburns
- Add
@CacheResult
and check calls and the console
@CacheResult(cacheName = "developers")
- Remove the developer and check the console is still there
http delete localhost:8080/hello/wburns
http localhost:8080/hello/wburns
- Use
@CacheInvalidate
, retry and check the console
@CacheInvalidate(cacheName = "developers")
http delete localhost:8080/hello/wburns
http localhost:8080/hello/wburns
- Use
@CacheInvalidateAll
, to remove all and check the console
- Add indexing model:
- create the package
org.infinispan.search
- add java classes:
Author
,Book
,Review
,BooksSchema
- Build and star the dev mode
./mvnw compile quarkus:dev
-
Show the schemas on Infinispan console
-
Highlight the fact that in production you should set:
quarkus.infinispan-client.use-schema-registration=false
- Create the cache
books
(startupMode => Replicated, None, local-indexed, indexed entities => insights.book)
- download the file (yaml)
- Copy file books.yaml => main/resources/
- add to application.properties
quarkus.infinispan-client.cache.books.configuration-uri=books.yaml
-
Copy
ModelGenerator
toorg.infinispan.search.generator
- Copy
BookResource
toorg.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'
- Copy
-
Test showcases
- Copy
SearchTest
toorg.infinispan.search
- Show the test cases
- 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
- Find the bridge network address ip for it:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' jaeger
- 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
- 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.";
}
- Build and run the dev mode:
./mvnw compile quarkus:dev
- Curl the endpoint
http PUT localhost:8080/hello/async/10
http PUT localhost:8080/hello/bulk/10