Open DevShivmohan opened 1 year ago
public interface CarRepository extends JpaRepository<TRace, String> {
@Query(nativeQuery = true, value = "select * from car_records where carVinNo = :vinNo and carSerialNo >= :serialNo")
List<Car> retrieveCars(@Param("vinNo") Long vinNo,@Param("serialNo") Long serialNo);
}
- **Indexed parameter**.
public interface CarRepository extends JpaRepository<TRace, String> {
@Query(nativeQuery = true, value = "select * from car_records where carVinNo = ?1 and carSerialNo >= ?2")
List
URL - https://jservice.io/api/random HttpMethod - GET
Object model class
package org.shiv.razorpay.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RandomObject {
private Integer id;
private String answer;
private String question;
private Integer value;
private String airdate;
private String created_at;
private String updated_at;
private Integer category_id;
private Integer game_id;
private Integer invalid_count;
private Category category;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
class Category{
private Integer id;
private String title;
private String created_at;
private String updated_at;
private Integer clues_count;
}
Requesting for URL
@GetMapping("/test")
public ResponseEntity<?> gettest(){
var response= restTemplate.getForEntity("https://jservice.io/api/random", RandomObject[].class);
System.out.println("Actual data");
RandomObject randomObject=Objects.requireNonNull(response.getBody())[0];
System.out.println(randomObject);
return ResponseEntity.status(HttpStatus.OK).body(response.getBody());
}
There are two way to manage the consistency in microservices is also called as SAGA pattern -
Microservices communication using RestTemplate
declare RestTemplate as a bean with Load balance, @LoadBalanced is mandatory otherwise not working by service name