У меня есть два микросервиса, которые называются grpcLogin и grpcCityPlace.
Которые связаны с grps и друг с другом, имеющими отдельный источник данных.
Из microservis grpcLogin я называю microservis grpcCityPlace.
Я хочу, чтобы операция Microservis grpcCityPlace была откатана в случае возникновения ошибки в Microservice grpcLogin.
Как я могу выполнить операцию отката для микросервиса grpcCityPlace с помощью микросервиса grpcLogin с загрузкой пружины и grp c?
Мне также нужен откат операций удаления и обновления.
grpcLogin:
public AdminUserModel create(@NotNull AdminUserModel adminUserModel) throws UtilityException, IllegalAccessException, BusinessException, InvocationTargetException {
//create Admin
AdminUser adminUser = new AdminUser();
adminUser.setFirstName(adminUserModel.getFirstName());
adminUser.setLastName(adminUserModel.getLastName());
adminUser.setPassword(PasswordEncoderGenerator.generate(adminUserModel.getPassword()));
adminUser.setUsername(adminUserModel.getUsername());
adminUser.setDateOfBirth(CalendarTools.getDateFromCustomDate(adminUserModel.getDateOfBirth()));
adminUser.setGender(etcItemService.findByIdAndCheckEntity(adminUserModel.getGender_id(), GenderEnum.class,null,true));
adminUser = adminUserRepository.save(adminUser);
//add cityPlace For Admin
CreateRequestModel createRequestModel = CreateRequestModel.newBuilder()
.setAdminUserId(adminUser.getId())
.setCityId(cityReadOneResponse.getId())
.setLatitude("35.791354")
.setLongitude("51.356406")
.setTitle("OfficePlace")
.build();
//call grpcCreate
final CreateResponseModel createResponseModel= this.cityPlaceStub.grpcCreate(createRequestModel);
//It's just written to express what I mean.
if(true){
throw new Exception();
}
adminUserModel.setId(adminUser.getId());
return adminUserModel;
}
grpcCityPlace:
@Override
public void grpcCreate(CreateRequestModel createRequestModel, StreamObserver<CreateResponseModel> responseObserver) {
CreateResponseModel.Builder createResponseModel = CreateResponseModel.newBuilder();
CityPlaceModel cityPlaceModel = new CityPlaceModel();
cityPlaceModel.setCity_id(createRequestModel.getCityId());
cityPlaceModel.setLatitude(createRequestModel.getLatitude());
cityPlaceModel.setLongitude(createRequestModel.getLongitude());
cityPlaceModel.setAdminUserId(createRequestModel.getAdminUserId());
cityPlaceModel.setTitle(createRequestModel.getTitle());
CityPlace cityPlace = new CityPlace();
cityPlace.setAdminUserId(cityPlaceModel.getAdminUserId());
City city = cityRepository.findById(cityPlaceModel.getCity_id()).get();
cityPlace.setCity(city);
cityPlace.setLatitude(cityPlaceModel.getLatitude());
cityPlace.setLongitude(cityPlaceModel.getLongitude());
cityPlace.setTitle(cityPlaceModel.getTitle());
cityPlace = cityPlaceRepository.save(cityPlace);
cityPlaceModel = this.create(cityPlaceModel);
responseObserver.onNext(createResponseModel.build());
responseObserver.onCompleted();
}