Code Monkey home page Code Monkey logo

agoncal-fascicle-quarkus-pract's Introduction

AGoncal Fascicle: Practising Quarkus Fascicle

Code of my Practising Quarkus Fascicle

Travis

Microservices is an architectural style that structures an application as a collection of distributed services. Microservices are certainly appealing but there are many questions that should be asked prior to diving into this architectural style: How do I deal with an unreliable network in a distributed architecture? How do I test my services? How do I monitor them? How do I package and execute them?

That's when Quarkus comes into play.

In this fascicle you will develop an entire microservice application using Quarkus as well as MicroProfile. You will expose REST endpoints using JAX-RS and OpenAPI, customise the JSON output thanks to JSON-B and deal with persistence and transaction with Hibernate ORM with Panache and JTA. Having distributed microservices, you will implement health checks and add some metrics so you can monitor your microservice architecture. Finally, thanks to GraalVM you will build native executables, and package and execute them with Docker.

This fascicle is very practical. It is the companion book of the more theoretical Understanding Quarkus where you’ll learn more about Quarkus, MicroProfile, REST and reactive microservices, as well as Cloud Native and GraalVM.

Practising Quarkus

Foreword by Clement Escoffier

I started learning Java in 1999. Over the past 20 years, I have witnessed the journey that Java and its ecosystem have been on. But 20 years is a long time, especially for software. Many trends have been called the "next big thing" only to then fade away. How many times have we read about the supposed death of Java? But it is still very much alive!

Corba, Applet, JavaEE, Spring, OSGi, Android, OpenJDK... all of these technologies have shaped the Java we know today. All of these technologies have pushed the limits of Java and have led to an increase in its versatility. That's how Java has endured across the ages: by adapting itself.

Nowadays, Java is facing another challenge. The rise of the Cloud, Containers and Serverless has pushed Java away from the spotlight. Until now, until Quarkus.

And, there is no better way to start with Quarkus than with this fascicle (and its companion fascicle {quarkus-book-title}). The extensive expertise of Antonio is the perfect tool to guide you towards new horizons. You are going to see live how Quarkus mutates Java to make it relevant in Containers, on Kubernetes and in Serverless environments. From the first line of code to production monitoring, this fascicle is your companion. Fasten your seat belt, and get ready to take off!

Clement Escoffier
Vert.x and Quarkus Core Developer at Red Hat
clementplop

And thanks to my proof-reader team:

References

agoncal-fascicle-quarkus-pract's People

Contributors

agoncal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

agoncal-fascicle-quarkus-pract's Issues

Add /ping from the beginning

In both rest endpoints, add the @Path("/ping") from the beginning and change the test

Rename @Path("/ping") to @Path("/hello")

mvn install throws build failure

When I try to run "mvn install" on Windows, I get the next error:

Failed to execute goal io.quarkus:quarkus-maven-plugin:1.9.0.Final:build (default) on project ui-bookstore: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.container.image.deployment.ContainerImageProcessor#publishImageInfo threw an exception: java.lang.IllegalArgumentException: The supplied combination of container-image group 'andrei gabor' and name 'ui-bookstore' is invalid
[ERROR] at io.quarkus.container.image.deployment.ContainerImageProcessor.publishImageInfo(ContainerImageProcessor.java:47)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:936)
[ERROR] at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR] at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
[ERROR] at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] at org.jboss.threads.JBossThread.run(JBossThread.java:479)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :ui-bookstore

Can somebody help me please?

Add a DB viewer

Despite the IDE, it would be good to have a section on how to install a DB tool (eg. PGAdmin, Squirrel, etc.) and how to configure it to view the DB (in chapter 3)

Instructions unclear for number resource and properties.

Hi Team.

Just a bit of constructive feedback.

When following along with the instructions for Chapter 4 there is a bit of confusion. With developers delight in mind I just wanted to point it out to you.

The listing (4.2.1) for the NumberResource class given as:

@Path("/api/numbers/book")
public class NumberResource {
  private static final Logger LOGGER = Logger.getLogger(NumberResource.class);
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response generateBookNumbers() throws InterruptedException {
    LOGGER.info("Generating book numbers");
    Faker faker = new Faker();
    BookNumbers bookNumbers = new BookNumbers();
    bookNumbers.setIsbn10(faker.code().isbn10(separator));
    bookNumbers.setIsbn13(faker.code().isbn13(separator));
    bookNumbers.setAsin(faker.code().asin());
    bookNumbers.setEan8(faker.code().ean8());
    bookNumbers.setEan13(faker.code().ean13());
    bookNumbers.setGenerationDate(Instant.now());
    return Response.ok(bookNumbers).build();
    }
}

The next section(4.2.2) mentions the object model with this code.

public class BookNumbers {
  private String isbn10;
  private String isbn13;
  private String asin;
  private String ean8;
  private String ean13;
  private Instant generationDate;
}

The next sentence mentions "As you can see, the definition for the separator is missing and for that reason, the code of the
Number REST endpoint does not compile yet...."

However the property is missing from both the classes. I could work out where the property is supposed to go by looking at the completed examples however it required me to do a bit of back tracking. If you added the property to the code in the example it would make it easier to follow for developers... making them happy.

Thanks for the effort.

Can't get Docker image

Hello,

When I run mvn install I get the FAILURE. What should I do to have SUCCESS message for Books REST Microservice?

Thanks.

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Practising Quarkus 1.0-SNAPSHOT:
[INFO]
[INFO] Practising Quarkus :: First Step ................... SUCCESS [ 20.221 s]
[INFO] Practising Quarkus ................................. SUCCESS [ 0.050 s]
[INFO] Practising Quarkus :: Infrastructure ............... SUCCESS [ 0.331 s]
[INFO] Practising Quarkus :: Load ......................... SUCCESS [ 0.395 s]
[INFO] Practising Quarkus :: Books REST Microservice ...... FAILURE [ 13.355 s]
[INFO] Practising Quarkus :: Numbers REST Microservice .... SKIPPED
[INFO] Practising Quarkus :: UI Bookstore ................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.725 s
[INFO] Finished at: 2021-04-24T06:19:18+02:00
[INFO] ------------------------------------------------------------------------


Test set: org.agoncal.fascicle.quarkus.book.BookResourceTest

Tests run: 14, Failures: 0, Errors: 1, Skipped: 13, Time elapsed: 9.386 s <<< FAILURE! - in org.agoncal.fascicle.quarkus.book.BookResourceTest
org.agoncal.fascicle.quarkus.book.BookResourceTest.shouldGetInitialItems Time elapsed: 0.017 s <<< ERROR!
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.RuntimeException: Unable to start Quarkus test resource org.agoncal.fascicle.quarkus.book.infrastructure.Database@633fd91
Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=postgres:12.4, imagePullPolicy=DefaultPullPolicy())
Caused by: com.github.dockerjava.api.exception.NotFoundException:
Status 404: {"message":"No such image: testcontainers/ryuk:0.3.0"}

Add links to the UI

In the Angular app, create an "Admin" menu with links:

  • Prometheus
  • Swagger UI for both Number and Book microservices
  • Index.html for both the Number and Book microservices

Increment Call to Action

  • Increment 1 added the mvn exec:java
  • 4.2.2. Maven Dependencies
  • Bootstrap a Dummy Quarkus application

Add user & password to start DB container

When I compile the project, it has an error on database container starter.
I fix it adding user, password and database name:

version: "3"
services:
database:
image: "postgres:12.4"
container_name: "books-database"
environment:
- POSTGRES_USER= bookstore
- POSTGRES_PASSWORD= bookstore
- POSTGRES_DB= books_database

ports:
- "5432:5432"
volumes:
- ./db-init/initialize-databases.sql:/docker-entrypoint-initdb.d/init.sql

monitoring:
image: "prom/prometheus:v2.21.0"
container_name: "books-monitoring"
ports:
- 9090:9090
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml

ui-vintage: bootstrap install doesn't work as documented

Trying to install bootstrap as documented in README.md doesn't work, as shown below:

$ ng add @ng-bootstrap/ng-bootstrap@bootstrap5
ℹ Using package manager: npm
✖ Unable to fetch package information for '@ng-bootstrap/ng-bootstrap@bootstrap5': No matching version found for @ng-  bootstrap/ng-bootstrap@bootstrap5.

Using angular 16.2.2

$ ng version

Angular CLI: 16.2.2
Node: 18.18.0
Package Manager: npm 9.8.1
OS: linux x64

Angular: 16.2.5
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
--------------------------------------------------------- 
@angular-devkit/architect       0.1602.2
@angular-devkit/build-angular   16.2.2
@angular-devkit/core            16.2.2
@angular-devkit/schematics      16.2.2
@angular/cli                    16.2.2
@schematics/angular             16.2.2
rxjs                            7.8.1
typescript                      5.1.6
zone.js                         0.13.3

No such file or directory

[vinicio@fedora infrastructure]$ docker-compose -f ./docker-compose.yaml up -d
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib64/python3.9/http/client.py", line 1253, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1299, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1248, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1008, in _send_output
self.send(msg)
File "/usr/lib64/python3.9/http/client.py", line 948, in send
self.connect()
File "/usr/lib/python3.9/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/usr/lib/python3.9/site-packages/urllib3/util/retry.py", line 403, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.9/site-packages/urllib3/packages/six.py", line 708, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3.9/site-packages/urllib3/connectionpool.py", line 392, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib64/python3.9/http/client.py", line 1253, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1299, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1248, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib64/python3.9/http/client.py", line 1008, in _send_output
self.send(msg)
File "/usr/lib64/python3.9/http/client.py", line 948, in send
self.connect()
File "/usr/lib/python3.9/site-packages/docker/transport/unixconn.py", line 43, in connect
sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/docker/api/client.py", line 214, in _retrieve_server_version
return self.version(api_version=False)["ApiVersion"]
File "/usr/lib/python3.9/site-packages/docker/api/daemon.py", line 181, in version
return self._result(self._get(url), json=True)
File "/usr/lib/python3.9/site-packages/docker/utils/decorators.py", line 46, in inner
return f(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/docker/api/client.py", line 237, in _get
return self.get(url, **self._set_request_timeout(kwargs))
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.9/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/docker-compose", line 33, in
sys.exit(load_entry_point('docker-compose==1.28.6', 'console_scripts', 'docker-compose')())
File "/usr/lib/python3.9/site-packages/compose/cli/main.py", line 81, in main
command_func()
File "/usr/lib/python3.9/site-packages/compose/cli/main.py", line 198, in perform_command
project = project_from_options('.', options)
File "/usr/lib/python3.9/site-packages/compose/cli/command.py", line 60, in project_from_options
return get_project(
File "/usr/lib/python3.9/site-packages/compose/cli/command.py", line 152, in get_project
client = get_client(
File "/usr/lib/python3.9/site-packages/compose/cli/docker_client.py", line 41, in get_client
client = docker_client(
File "/usr/lib/python3.9/site-packages/compose/cli/docker_client.py", line 170, in docker_client
client = APIClient(use_ssh_client=not use_paramiko_ssh, **kwargs)
File "/usr/lib/python3.9/site-packages/docker/api/client.py", line 197, in init
self._version = self._retrieve_server_version()
File "/usr/lib/python3.9/site-packages/docker/api/client.py", line 221, in _retrieve_server_version
raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.