NOTE: This tutorial is using outdated as it's using Spring Boot 2, I am working on an update for this tutorial. Please refer to the github repo, whenever you are facing any issue with the dependency or compilation errors: github.com/SaiUpadhyayula/spring-boot-microservices
I love the fact that you choice web client to sync communication and the way that you explain it, you're amazing. Thank you!, also I love the fact that you're very organized and that you teach to use construct injections instead of field injection. 10/10
Excellent series to start with microservices. Absolutely loved the series. Thanks you. Lots of things to learn. Java promotes code reusability as a programming paradigm. The InventoryResponse class from the Inventory DTO is duplicated in Order Service DTO. We also faced a similar situation while migrating from a monolith to microservices. To handle the situation we created a module with common classes and added that module as a dependency to all the microservices. Pros is, code duplication is avoided and the microservices are still deployed as independent entity. Cons is, the common module has to be built before building any of the microservices. Whats the best practice to share a dto across microservices?
at 23:37 is replacing by a method reference the correct code? I did not see any methods for getting the isInStock variable inside the InventoryResponse class
Great presentation, love the way you teach, I guess there's a minor bug here that we need to consider the Order quantity as well to find the available inventory stock for each skucode.
Nice! We should add a service discovery so we dont have the need to specify the ports. That’s probably what you’ll do in the next one, right? Great video! Thanks!!!
Bug sur, for example if we have a order request with at least on skuCode instock, and others skucodes not existing in database, we can always place Order!! 😇 { "orderLineItemsDtoList":[ { "skucode": "iphone_13", "price": 100, "quantity":1 }, { "skucode": "bla_bla", "price": 100, "quantity":1 } ] } any way that's a Great Tutorial, i learn a lot thanks
@@jackfeng9202 my solution @Transactional(readOnly = true) @Override public List isInStock(List skuCode) { int skuReq = skuCode.size(); List inventories = inventoryRepository.findBySkuCodeIn(skuCode); int skuRes = inventories.size(); List results = new ArrayList(); for (Inventory inventory : inventories) { if (skuReq != skuRes) { throw new IllegalArgumentException("Sku code not valid"); } else { results.add(InventoryResponseDTO.builder() .skuCode(inventory.getSkuCode()) .isInStock(inventory.getQuantity() > 0) .build()); } } return results; }
is the skucode really enough as a request param? dont we also have to include the quantity? for example if there are 3 iphones ordered and only 2 in stock it should fail. but if you go to min 17:47 the isInStock method does not check for quantity, it checks only if there is at least one item in stock... or am i thinking wrong? thanks in advance and thanks for the video...really helpful.
Please note that the implementation is not perfect and have gaps. I was mainly concentrating on getting to the more interesting parts, that's why I took some shortcuts during implementation.
@Programming Techie : Could you please display the error message " Product is not in stock , please try again later" in the POSTMAN instead in IntelliJ Idea console
Why should we check for each item if available or not before ordering ? We could have probably set a flag in product service so that we don't display item if not in stock or label as out of stock. Checking of each item in OrderController is not something I would go for.
instead of sending back Inventory Response to Order Service then check all match or not , i think it is better to check in Inventoryservice and sending back true/false
Hey, one question: Why duplicate the InventoryResponse class? If these two services are designed to communicate with each other, we could add the inventory dto as a dependency to the order-service project, right?
That's one way to go usually you have the option to either maintain the required classes as shared library and add them as dependency (or) duplicate the classes across the services You can go with either option.
I have just started learning your course, but I'm not sure which chapter to begin with. I see two courses on Spring Microservices. One of them is a project example. Could you please guide me on where to start?
Hi, I love your tutorial thus far, and you make so easy to understand and follow you. I was wondering if you had a beginner course on Spring boot that explains concepts like bean etc? Thank you in anticipation of your response.
I am getting 404 error request while hitting the inventory API in postman. As a result I am unable to get the Out of stock message and Order placed successfully message. Could you please tell me how to fix it?
Great Tutorial so far!! I am actually coding along with you, I have just one question, not sure if you already took care of it in the future videos, but after placing the order from order service, shouldn't the inventory table column quantity decrease by the quantity ordered ?
Thanks, I actually didn't want to spend too much time coding the business logic, The plan is to concentrate more on the microservice concepts. So yes, the inventory update part is missing, but I will not be covering in the future tutorials too.
Can anybody tell me why i am getting this error while running the inventory service ....... Name for argument of type [java.util.List] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag
10 месяцев назад
Using the block() operator is an anti-pattern. But thanks for the video.
in the postman when i click send it's giving me an exception "java.sql.SQLException: Field 'id' doesn't have a default value". how to solve this problem all my code is the same
allMatch would cause problem since the stream is empty then true is returned. E.g. if you order iPad your order still would be placed even your inventory has no iPad.
You are right, I didn't put much thought into the logic as I was mainly thinking about creating surrounding services, this logic will have multiple edge cases to handle, I will update the source code once the tutorial is completed.
For interservice communication why can't we use feignclient instead of webclient. Feignclient can be integrated with spring API Gateway for load balancing and url routing very easily. Can you check on that too.
Now, I have a problem adding EurekaClientAnnotation, the maven dependency was dowloaded but I have this error: java: cannot find symbol symbol: class EnableEurekaClient, anyone facing the same issue [spring-cloud version: 2022.0.2]
Hi, This Tutorial is really helpful. Thanks is not enough but a million thanks. Please help with below query interviewer: How are you securing ur APIs/endpoints me: we implemented security by using JWT interviewer: if I have an API and that API internally calls an external API, how do you authenticate the external API? are you using the same jwt token to authenticate internal/external APIs? or if you are using 2 jwt tokens, then u r calling JWT server twice which is not good? So actually he confused me, and I was blank Please give me a perfect solution, Thanks in advance
Hi, The answer depends on how you define an external API, is the external API secured by the same authorization server ? ( In your words jwt server ?) Then there is no need to get another token from the server, you can simply use this token itself. Spring Cloud Gateway can do this automatically for you, it's called as Token Relay, google about it to know more details. If the external API is not secured by the same authorization server, ie, you are calling an API outside your organization, then you have to call the respective authorization server and get a new JWT. You can checkout the older microservices series in my channel, refer to the updated video on API Gateway and Keycloak, I explained this in detail.
Just created it as a standalone service, Initially also wanted to create a UI, for this tutorial, ie. fetch the products from product service and then place the order, but I changed my mind and just left the service as it is.
@@ProgrammingTechie Can you do the complete tutorial for the Product Service? I would like to learn how I can implement the backend to the frontend(UI)
you actually wasting time bro, the reason why we come to the springboot because of all the configurations to do in maven project and you are again doing all by yourself. you know you can directly call the springboot projects and make a communication between them using API gateway
anybody facing issue with lombok builder I am getting many things but it is not working java: cannot find symbol symbol: method builder() location: class com.utech.inventoryservice.dto.InventoryResponse
NOTE: This tutorial is using outdated as it's using Spring Boot 2, I am working on an update for this tutorial. Please refer to the github repo, whenever you are facing any issue with the dependency or compilation errors: github.com/SaiUpadhyayula/spring-boot-microservices
I love the fact that you choice web client to sync communication and the way that you explain it, you're amazing. Thank you!, also I love the fact that you're very organized and that you teach to use construct injections instead of field injection. 10/10
Excellent series to start with microservices. Absolutely loved the series. Thanks you. Lots of things to learn.
Java promotes code reusability as a programming paradigm. The InventoryResponse class from the Inventory DTO is duplicated in Order Service DTO. We also faced a similar situation while migrating from a monolith to microservices. To handle the situation we created a module with common classes and added that module as a dependency to all the microservices. Pros is, code duplication is avoided and the microservices are still deployed as independent entity. Cons is, the common module has to be built before building any of the microservices. Whats the best practice to share a dto across microservices?
at 23:37 is replacing by a method reference the correct code? I did not see any methods for getting the isInStock variable inside the InventoryResponse class
Great presentation, love the way you teach, I guess there's a minor bug here that we need to consider the Order quantity as well to find the available inventory stock for each skucode.
Thanks for tutorial. Just whant to add that, when inventoryResponses empty then stream.allMatch returns true. Need to add check ifnot empty.
Very informative video, thanks for your efforts
Nice! We should add a service discovery so we dont have the need to specify the ports. That’s probably what you’ll do in the next one, right? Great video! Thanks!!!
Exactly 🙂
Bug sur, for example if we have a order request with at least on skuCode instock, and others skucodes not existing in database, we can always place Order!! 😇 {
"orderLineItemsDtoList":[
{
"skucode": "iphone_13",
"price": 100,
"quantity":1
},
{
"skucode": "bla_bla",
"price": 100,
"quantity":1
}
]
}
any way that's a Great Tutorial, i learn a lot thanks
I face the same issue, have you figure out why the error occur?
@@jackfeng9202 my solution
@Transactional(readOnly = true)
@Override
public List isInStock(List skuCode) {
int skuReq = skuCode.size();
List inventories = inventoryRepository.findBySkuCodeIn(skuCode);
int skuRes = inventories.size();
List results = new ArrayList();
for (Inventory inventory : inventories) {
if (skuReq != skuRes) {
throw new IllegalArgumentException("Sku code not valid");
} else {
results.add(InventoryResponseDTO.builder()
.skuCode(inventory.getSkuCode())
.isInStock(inventory.getQuantity() > 0)
.build());
}
}
return results;
}
is the skucode really enough as a request param? dont we also have to include the quantity? for example if there are 3 iphones ordered and only 2 in stock it should fail. but if you go to min 17:47 the isInStock method does not check for quantity, it checks only if there is at least one item in stock... or am i thinking wrong? thanks in advance and thanks for the video...really helpful.
Please note that the implementation is not perfect and have gaps.
I was mainly concentrating on getting to the more interesting parts, that's why I took some shortcuts during implementation.
very good!
Awesome! ❤
@Programming Techie : Could you please display the error message " Product is not in stock , please try again later" in the POSTMAN instead in IntelliJ Idea console
Why should we check for each item if available or not before ordering ? We could have probably set a flag in product service so that we don't display item if not in stock or label as out of stock. Checking of each item in OrderController is not something I would go for.
instead of sending back Inventory Response to Order Service then check all match or not , i think it is better to check in Inventoryservice and sending back true/false
Ur shared links for mongodb and spring test are same
Hey, one question: Why duplicate the InventoryResponse class? If these two services are designed to communicate with each other, we could add the inventory dto as a dependency to the order-service project, right?
That's one way to go usually you have the option to either maintain the required classes as shared library and add them as dependency (or) duplicate the classes across the services
You can go with either option.
Any chance you could make a follow up showing how to write a shared library with maven/gradle? Great video, thank you!
I have just started learning your course, but I'm not sure which chapter to begin with. I see two courses on Spring Microservices. One of them is a project example. Could you please guide me on where to start?
Refer the latest course
Just a thought to share, InventoryService can be added to OrderSvc as a dependency, and InventoryResponse can be accessed and reused.
how?
what about relationships im so confused so we have for exemple student that have many courses and each one is a microservice how can we do this
Hi, I love your tutorial thus far, and you make so easy to understand and follow you. I was wondering if you had a beginner course on Spring boot that explains concepts like bean etc? Thank you in anticipation of your response.
Thank you, you can check out my Spring Framework tutorial
ruclips.net/video/ZwcHeLhvuq4/видео.html
@@ProgrammingTechie thank you so much.
Pls make the webflux, react tutorial
I am getting 404 error request while hitting the inventory API in postman. As a result I am unable to get the Out of stock message and Order placed successfully message. Could you please tell me how to fix it?
What happens if they order more than is actually in stock?
Unable to find sku codes order is placed anyways.
I would like to enroll for this training
Wouldn’t this be a coupling? Because order services depends on inventory services to return.
Loose coupling it is.
Great Tutorial so far!! I am actually coding along with you, I have just one question, not sure if you already took care of it in the future videos, but after placing the order from order service, shouldn't the inventory table column quantity decrease by the quantity ordered ?
Thanks, I actually didn't want to spend too much time coding the business logic, The plan is to concentrate more on the microservice concepts.
So yes, the inventory update part is missing, but I will not be covering in the future tutorials too.
Bad practice (17:01).
Hey, how's that rainbow indents plugin called?
Can you point me to a link which has good content on Java Streams
Hey techie can I use your code as a starting point of a RUclips series thatI would make
Sure make sure to mention this tutorial 😄
Can anybody tell me why i am getting this error while running the inventory service .......
Name for argument of type [java.util.List] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag
Using the block() operator is an anti-pattern.
But thanks for the video.
in the postman when i click send it's giving me an exception "java.sql.SQLException: Field 'id' doesn't have a default value". how to solve this problem all my code is the same
The block() method should not be used and generates an error. Is there any other way to create synchronous inter services communication?
use @FeignClient declarative mode to call another API easy and conveinance way
allMatch would cause problem since the stream is empty then true is returned. E.g. if you order iPad your order still would be placed even your inventory has no iPad.
You are right, I didn't put much thought into the logic as I was mainly thinking about creating surrounding services, this logic will have multiple edge cases to handle, I will update the source code once the tutorial is completed.
why not using feign client??
For interservice communication why can't we use feignclient instead of webclient. Feignclient can be integrated with spring API Gateway for load balancing and url routing very easily. Can you check on that too.
I will introduce it later in the tutorial, it's part of the plan 🙂
@@ProgrammingTechie oh ok. Got it
Now, I have a problem adding EurekaClientAnnotation, the maven dependency was dowloaded but I have this error: java: cannot find symbol
symbol: class EnableEurekaClient, anyone facing the same issue [spring-cloud version: 2022.0.2]
Hi, This Tutorial is really helpful. Thanks is not enough but a million thanks. Please help with below query
interviewer: How are you securing ur APIs/endpoints
me: we implemented security by using JWT
interviewer: if I have an API and that API internally calls an external API, how do you authenticate the external API?
are you using the same jwt token to authenticate internal/external APIs?
or if you are using 2 jwt tokens, then u r calling JWT server twice which is not good?
So actually he confused me, and I was blank
Please give me a perfect solution, Thanks in advance
Hi,
The answer depends on how you define an external API, is the external API secured by the same authorization server ? ( In your words jwt server ?) Then there is no need to get another token from the server, you can simply use this token itself.
Spring Cloud Gateway can do this automatically for you, it's called as Token Relay, google about it to know more details.
If the external API is not secured by the same authorization server, ie, you are calling an API outside your organization, then you have to call the respective authorization server and get a new JWT.
You can checkout the older microservices series in my channel, refer to the updated video on API Gateway and Keycloak, I explained this in detail.
@@ProgrammingTechie Thank you so much for ur rapid response. Will go through above suggested way
Thanks again
at 26:24 ruclips.net/video/D_XxZU72yMw/видео.html it's giving me an Error: Field 'id' doesn't have a default value. how to solve this problem please
What is the mean of "OrderLineItems"? What we use for? Can somebody explain?
go to your database, select* all tables in your db and you will understand
Can you make the same course with quarkus framework
Sorry no plans to do this in the near future.
Next part video when can we expect sir ?
On Tuesday about Service Discovery
@@ProgrammingTechie thanks sir
@@ProgrammingTechie thanks you!!
Order gets placd even if sku not matches.
I am getting 404 error request while hiiting the inventory api in postman . can someone please help???
did u find a sol
In the InventoryRepository change the "Optional findBySkuCodeIn(List skuCode);" to "List findBySkuCodeIn(List skuCode);"
Mobile view can't see font
Why would you have REST communication between internal services? Such a waste.
Sure we can use gRPC, I didn't want to make this tutorial more complicated.
@@ProgrammingTechie Tried and true messaging probably best.
How to handle fallback here?
This will be part of the Circuit Breaker Pattern video, which will be covered in Part 6
Sir can u please send me this project's source code 🙏
What is the point of the Product Service?
Just created it as a standalone service, Initially also wanted to create a UI, for this tutorial, ie. fetch the products from product service and then place the order, but I changed my mind and just left the service as it is.
@@ProgrammingTechie why is it created so
Thanks. It was good to learn how to connect to MongoDB anyway
@@ProgrammingTechie Can you do the complete tutorial for the Product Service? I would like to learn how I can implement the backend to the frontend(UI)
Found the issue it was an empty stream.
Spring Data MongoDB Tutorial: I think you mistake here with a link
you actually wasting time bro, the reason why we come to the springboot because of all the configurations to do in maven project and you are again doing all by yourself.
you know you can directly call the springboot projects and make a communication between them using API gateway
anybody facing issue with lombok builder
I am getting many things but it is not working
java: cannot find symbol
symbol: method builder()
location: class com.utech.inventoryservice.dto.InventoryResponse