Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Last active June 7, 2021 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamBien/38e1754782c901f5d63e45968f3df610 to your computer and use it in GitHub Desktop.
Save AdamBien/38e1754782c901f5d63e45968f3df610 to your computer and use it in GitHub Desktop.
87thAirhacksQ&A.md

Ask questions and see you at June, 7th, 8.PM. CEST: https://youtu.be/Uz1nLi5APVw

Also checkout recent episode:

86th airhacks.tv

Please keep the questions Jakarta EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions. Upcoming airhacks.tv events are also going to be announced at meetup.com/airhacks

@avdia98
Copy link

avdia98 commented May 20, 2021

Hi Adam,

if I use Microprofile metrics, and i want to manually count something for e.g. how many 404 responses in some api calls, I know how to do that in a single instance. But in a Kubernetes cluster, if I would scale replicas of pod the microprofile metrics are per pod, how can I get metrics from all same replicas of same pod and to get total number of 404 responses?

How can I make the /metrics path with authentication in Quarkus?

Thank you

@dev87sal
Copy link

Hello Adam

We are splitting our monolith app into microservices. In first iteration, this splitting process wouldn't be perfect because 2 microservice would use same database under different schemes. Assume that there are 2 microservices. A and B. Microservice A would start a transaction and if in case of microservice B writes the data to database I would assume that this transaction is completed successfully. In case of error I would like to rollback this transaction from A and B. How can we use XA transactions? What would you advise? Any patterns? Thanks.

@HiMyNameIsIlNano
Copy link

Hello Adam,

I have recently discovered your YouTube channel and I really like it.

I have a question regarding the package structure of your Java applications. You make extensive use of the BCE term. Let us just say I have a create operation that goes through a controller, the controller performs a call to another service to run some business logic and the business logic finally calls a Dao/repository to save data into the DB. While the controller is to be created under the Boundary and the Dao in the Entity package where would you put the business logic?

Thanks in advance,
HiMyNameIsIlNano

@dempile
Copy link

dempile commented May 25, 2021

Hi adam,

  1. Iam working on a project with jakarta EE 8 , Primefaces running on Payara, when I make changes and deploy I have this kind of error and Iam forced to restart the server to make it run.
    I know its a strange error because its the casting of same type of object but it makes me lose alot of time in restarting server. maybe you faced it before. Maybe its related to the servletfilter because I always test for security in every call of a pages.

[2021-05-25T19:21:20.180+0100] [Payara 5.201] [AVERTISSEMENT] [] [javax.enterprise.web] [tid: _ThreadID=88 _ThreadName=http-thread-pool::http-listener-1(2)] [timeMillis: 1621966880180] [levelValue: 900] [[
StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: class dz.eadn.admin.business.entity.User cannot be cast to class dz.eadn.admin.business.entity.User (com.exemple.admin.business.entity.User is in unnamed module of loader org.glassfish.web.loader.WebappClassLoader @3c9aad7c; com.exemple.admin.business.entity.User is in unnamed module of loader org.glassfish.web.loader.WebappClassLoader @6358dc10)

  1. In a cloud environnement , do you still use Docker to develop and after finishing the app push it to Kubernetes cluster in a two time process or you directly develop and deploy the app in the Kubernetes cluster, someting like Jenkins X.

Thanks

@thehpi
Copy link

thehpi commented May 26, 2021

What would be the advantage of using a Stateless EJB vs a Singleton EJB with bean managed concurrency.
I know stateless beans have a pool of beans from which a free bean is taken.
But when the bean does e.g. a time intensive operation then the pool might be empty and block new requests while a Singleton would continue.

@thehpi
Copy link

thehpi commented May 26, 2021

I heard you say several times that you never use an ear and you only use wars. I know there are several issues with using ear's probably because some specs do not define the behaviour when an ear is used and as such I understand why you would not use an ear.

But how would you then handle it when you need some bean that is to be used by all wars. In an ear, all wars can use it.
I can imagine if it's a jar with code and no state then you could include it in every war but if it's big then it would duplicate jars.
But if it's some bean with a central state like a cache or some client that you really only want to instantiate once, how would you handle that.

Of course you could wrap things in a rest api so wars could call each other but that would slow things down because of the extra http communication layer.

@yllber2001
Copy link

Hi Adam,

I was just testing around mp fault tolerance bulkhead pattern. I have not much knowledge before for it.

In my example I created a simple restmethod that blocks (thread.sleep) and after that sleep I returned dummy String.
I set @bulkhead(1), I went and test from chrome to see if it allows more than one, I opened multipled tabs at same time and all tabs were waiting for result, no BulkheadException was thrown..

But if I opened another incognito instance of chrome, and hit the bulkhead at same time from both chromes (incognito and non-incognito) in one of them I get the BulkheadException immediately?

So I don't get it, does bulkhead checks for tcp connection number exceed or the thread number exceed,
Cause I know that Chrome for a specific http url, opens a tcp connections and keep-alive it until the chrome is closed, so if you open incognito chrome, that means that you have now two tcp connections?

So, does @bulkhead(1) allow only one tcp connection at a time, or thread at a time?

I printed in console currentThreadName, and even with thread.sleep(1000), if you open multiple tabs and hit url, all of them prints in console same thread number (in my case executor-thread-199, using quarkus)? Why does that happen, shouldn't it hit different thread each time it is called?

p.s. I'm still a student and maybe I confuse things and I confuse the way I ask my question, but I don't get it... 😄

Thank you

@stefancreator
Copy link

stefancreator commented May 27, 2021

Hello Adam,

  1. What is difference between java.util.Logger, java.lang.Logger and loggers from logging libraries e.g. slf4j, log4j? Which one to use? Why so many different loggers?

  2. What do you think of Unit tests, if I am correct in some of your shows, conferences you don't mention them so much? Should unit tests be used a lot, as they say in Internet that there should be so much unit testing because without doing unit tests you're a bad developer...

  3. Using mp rest client and quarkus and two services A and B, when I make call from A service to B service (also built with quarkus) oif response from B isn't OK (200 code) cause maybe service B throwed exception, how to get the http code in A service and not to throw the exception from B also in service A;

// In service A:
line 1: Response resp = restClient.callServiceB();
line 2: if (resp.getStatus() != 200) {
//do my own logic...
}
I want to say that I can't reach my line 2, because the exception that is thrown from service B is automatically thrown from service A (in line 1)
How does that happen, how can (in my case quarkus) know that from a simple http call the service B is also Java and make the exception the same as if it would happen in service A)

Thanks

@wanderer2097
Copy link

Hello Adam!

I was playing around with your BCE (front end edition) template and I have to admit - after the initial mindset change it is actually becoming quite intuitive!

One feedback item (or a question) - how would you implement something like JSON PATCH (RFC6902 - also described here) using your template? With redux capturing the history of changes in the background it would seem that there should be some way (or a hack) to transpose these actions into JSON PATCH as series of replace/add/etc. operations. Do you have any ideas? This could really help bridge the gap between "stateless REST" & "domain rich Gateway".

Seems most modern "public" API's (salesforce, OData-like, netsuite, paypal, JIRA, etc.) support PATCH in one way or another (albeit I see the MERGE (rfc7386) format more commonly). Curious to know - in your (mid-range enterprise projects/applications) - how do you typically see the update scenario handled for large, complex objects (e.g. work order with multiple line items, etc.)? Is it via PUT (i.e. idempotent, complete representation) or PATCH (i.e. just the delta)?

@wanderer2097
Copy link

wanderer2097 commented May 28, 2021

On your projects do you see ETag's (& preconditions If-Match) used as an optimistic concurrency control mechanism? If so - any problems/issues with using the JPA Entities' @Version for it?

@wanderer2097
Copy link

wanderer2097 commented May 28, 2021

(back to the BCE on the back-end)

Should the REST resource class in the boundary be @Transactional?

In some of your workshops/demos you make the REST resource a @stateless (in addition to the manager class which is and always should be @Stateless). Is that just a hack for the purpose of having the methods counted (and perhaps pooling) or do you actually intentionally want the transaction to start there (naturally @Stateless implies transactions)?

My understanding was that each discrete use case should be clearly starting in the protocol agnostic "manager" portion of the boundary whereas the REST resource class is just an "adapter" layer. Including REST methods in the transactions would be a "code smell" indicating that we are trying to do something outside of the "unit of work" scope that maybe should be part of it (i.e. executed atomically).

@wanderer2097
Copy link

Lastly - really looking forward to the Java on AWS Cloud workshop!

Would it be at all possible to include the following topics:

  1. Long running processes (how-to do it on AWS specifically). Example - we have a batch job which reads all customer invoices from the database, does something with them and writes something back to the database. Covering aspects like monitoring, controlling resource utilization, etc.
  2. Singleton in the cloud - how would one go about having a guaranteed single instance of a specific bean/microservice in the cloud environment?

The agenda looks pretty packed - if we can't cover it in the workshop I will try asking them here (refactored to the best of my abilities).

@shqiptaros
Copy link

Hi Adam

(1)
I've implemented an api gateway using quarkus that interacts with some other microservices (also on quarkus).

for each microservice i use an microprofile @restclient in api gateway,

How to make the microprofile @Retry to work only if there is a connection error (maybe the microservice is down)
I've tried @Retry(retryOn = java.net.ConnectException.class) but it does not work. Maybe didn't work cause the first exception that is thrown is (org.jboss.resteasy.spi.UnhandledException), but I think that this exception is thrown each time any kind of exception is thrown, so I don't want to @Retry(retryOn = UnhandledException) because I only want to Retry only if connection refused.

So, I want to do this: api gateway rest client to some service, if service is down I want to printStackTrace in log, to @Retry once more to connect and if two times not connected I want to return a JsonObject with a specific information to the client.

(2)
Can you explain shortly what is Flyway db, should it be used and if yes how should be used with Java, Jakarta EE or Quarkus or any java technology...

Thanks a lot in advance

@dev87sal
Copy link

Should we use Lombok project? Why? Why not? Thanks

@dev87sal
Copy link

What are the differences between integration test, smoke test, system test and unit test from your point of view? Thanks.

@dkrtic
Copy link

dkrtic commented Jun 4, 2021

Hi Adam,

can you please make your podcasts louder as it is quieter than all the other podcasts that I listen to.
There are some "standards" how loud the podcast should be so they are all on the approximately same level.

Thanks

@christian-frei
Copy link

Hi Adam,
Many old applications use the command chain pattern: Often there was a xml file describing the order of the commands, a parser and some boiler plate reflection code to execute the commands.
How would you encounter/refactor such a problem nowadays? CDI (async) events?

Thanks and looking forward to the aws workshop in July.

@HiMyNameIsIlNano
Copy link

HiMyNameIsIlNano commented Jun 7, 2021

Hi Adam,

what would be the preferred way to handle exceptions in a JakartaEE application?

Regards,
HiMyNameIsIlNano

@HiMyNameIsIlNano
Copy link

HiMyNameIsIlNano commented Jun 7, 2021

Hi Adam,

I would like to experiment a bit with "events" in my JakartaEE backend. My goal is to generate an event (e.g. OrderPlacedEvent) and have another service (e.g. ShippingServiceListener) in the backend that listens to that event and perform some taks (e.g. create a shipment and update the state of it in the DB). If I were to use Spring I would inject the:

@Autowired private ApplicationEventPublisher applicationEventPublisher;

in my service and define my ShippingServiceListener this way:

@Component public class ShippingServiceListener implements ApplicationListener<OrderPlacedEvent>

How can I achieve the same in a JakartaEE application?

Regards,
HiMyNameIsIlNano

@dev87sal
Copy link

dev87sal commented Jun 7, 2021

Should we use DTO objects? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment