This application exposes a REST service that, based on the sent request, consumes a remote REST API to store/retrieve data in a remote Data Grid Cluster. To achieve that, the application exposes two REST Endpoints:
- query/getData
- query/putData
- Create the person cache in your Data Grid installation :
<?xml version="1.0"?>
<distributed-cache name="person" owners="2" mode="SYNC" statistics="true">
<encoding>
<key media-type="x-protostream/x-protostream"/>
<value media-type="x-protostream/x-protostream"/>
</encoding>
</distributed-cache>
Json format:
{
"distributed-cache": {
"owners": "2",
"mode": "SYNC",
"statistics": true,
"encoding": {
"key": {
"media-type": "application/x-protostream"
},
"value": {
"media-type": "application/x-protostream"
}
}
}
}
- Add the authentication mechanisms for the rest-connector endpoint that includes
BASIC
in theinfinispan.xml
configuration file located in$RHDG_HOME/server/conf/
directory. Here is an example:
<endpoints>
<endpoint socket-binding="default" security-realm="default">
<hotrod-connector name="hotrod-default" socket-binding="default">
<authentication security-realm="default">
<sasl server-name="infinispan" mechanisms="SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256 SCRAM-SHA-1 DIGEST-SHA-512 DIGEST-SHA-384 DIGEST-SHA-256 DIGEST-SHA CRAM-MD5 DIGEST-MD5" qop="auth"/>
</authentication>
</hotrod-connector>
<rest-connector name="rest-default" socket-binding="default">
<authentication mechanisms="BASIC DIGEST" security-realm="default"/>
</rest-connector>
</endpoint>
</endpoints>
- Create a user and start the Data Grid instance:
$RHDG_HOME/bin/cli user create admin -p admin
$RHDG_HOME/bin/server.sh
- Clone the project:
git clone -b main https://github.com/alexbarbosa1989/quarkus-rest-client
- Upload
person.proto
schema provided in the app root directory to the running Data Grid server:
curl -u admin:admin -X POST --data-binary @./person.proto http://localhost:11222/rest/v2/caches/___protobuf_metadata/person.proto
- Execute the application in dev mode (More options in Quarkus basics section):
./mvnw compile quarkus:dev
- Update the
application.properties
file located inmain/src/main/resources/application.properties
with the credentials and Data Grid server URL. Here is the default provided in the current app:
quarkus.rest-client."com.redhat.test.rest.RemoteServiceClient".url=http://localhost:11222
dgserver.username=admin
dgserver.password=admin
-
Use the exposes REST endpoint:
5.a. Use the
query/putData/{key}
to put data in the external Data Grid cache:curl -X POST --header 'Content-Type: application/json' -d '{ "firstName": "Sadio", "lastName": "Mané", "bornYear": "1992", "bornIn": "Senegal" }' http://localhost:8080/query/putData/person1
5.b. Use the
query/getData/{key}
to put data in the external Data Grid cache:curl -X GET http://localhost:8080/query/getData/person1
This project uses Quarkus, the Supersonic Subatomic Java Framework.
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The application can be packaged using:
./mvnw package
It produces the quarkus-run.jar
file in the target/quarkus-app/
directory.
Be aware that it’s not an über-jar as the dependencies are copied into the target/quarkus-app/lib/
directory.
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar
.
If you want to build an über-ja 63B0 r, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application, packaged as an über-jar, is now runnable using java -jar target/*-runner.jar
.
You can create a native executable using:
./mvnw package -Dnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Dnative -Dquarkus.native.container-build=true
For Openshift deployment (Optional if require to trust Openshift cert quarkus.kubernetes-client.trust-certs=true
):
./mvnw install -Dquarkus.openshift.deploy=true -Dquarkus.kubernetes-client.trust-certs=true
You can then execute your native executable with: ./target/dg-client-1.0-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.
Easily start your Reactive RESTful Web Services