From 0480012bf2fe8d0ec2f3221e1e0f4fcfabbde713 Mon Sep 17 00:00:00 2001 From: Huynh Thanh Binh <1653006@student.hcmus.edu.vn> Date: Sun, 9 Aug 2020 02:09:59 +0700 Subject: [PATCH] [SERVER] fix bug on handshake: not storing parking lot id --- .../service/impl/HandshakeServiceImpl.java | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/service/contact-service/src/main/java/com/bht/saigonparking/service/contact/service/impl/HandshakeServiceImpl.java b/service/contact-service/src/main/java/com/bht/saigonparking/service/contact/service/impl/HandshakeServiceImpl.java index dd6ef66e..3f319946 100644 --- a/service/contact-service/src/main/java/com/bht/saigonparking/service/contact/service/impl/HandshakeServiceImpl.java +++ b/service/contact-service/src/main/java/com/bht/saigonparking/service/contact/service/impl/HandshakeServiceImpl.java @@ -20,7 +20,6 @@ import com.bht.saigonparking.service.contact.service.QueueService; import com.google.protobuf.Int64Value; -import io.grpc.stub.StreamObserver; import lombok.RequiredArgsConstructor; /** @@ -33,7 +32,7 @@ public final class HandshakeServiceImpl implements HandshakeService { private final QueueService queueService; private final AbstractMessageListenerContainer messageListenerContainer; - private final ParkingLotServiceGrpc.ParkingLotServiceStub parkingLotServiceStub; + private final ParkingLotServiceGrpc.ParkingLotServiceBlockingStub parkingLotServiceBlockingStub; @Override public Map postAuthentication(@NotNull SaigonParkingTokenBody tokenBody, boolean mustConsumeFromQueue) { @@ -56,33 +55,19 @@ public Map postAuthentication(@NotNull SaigonParkingTokenBody to if ("PARKING_LOT_EMPLOYEE".equals(userRole)) { try { - parkingLotServiceStub.getParkingLotIdByParkingLotEmployeeId(Int64Value.of(userId), new StreamObserver() { + long parkingLotId = parkingLotServiceBlockingStub + .getParkingLotIdByParkingLotEmployeeId(Int64Value.of(userId)) + .getValue(); - long parkingLotId; + attributes.put(SAIGON_PARKING_PARKING_LOT_ID_KEY, parkingLotId); - @Override - public void onNext(Int64Value int64Value) { - parkingLotId = int64Value.getValue(); + /* register auto-delete exchange for parking-lot and bind user auto-delete queue to it */ + queueService.registerAutoDeleteExchangeForParkingLot(parkingLotId, userQueue); - attributes.put(SAIGON_PARKING_PARKING_LOT_ID_KEY, parkingLotId); + LoggingUtil.log(Level.INFO, "SERVICE", "Success", + String.format("registerAutoDeleteExchangeForParkingLot(%d)", parkingLotId)); - /* register auto-delete exchange for parking-lot and bind user auto-delete queue to it */ - queueService.registerAutoDeleteExchangeForParkingLot(parkingLotId, userQueue); - } - - @Override - public void onError(Throwable throwable) { - throw new PostAuthenticationException(); - } - - @Override - public void onCompleted() { - LoggingUtil.log(Level.INFO, "SERVICE", "Success", - String.format("registerAutoDeleteExchangeForParkingLot(%d)", parkingLotId)); - } - }); } catch (Exception exception) { - /* if exception occurs, immediately remove listen to queue */ /* as queue has no one listen to it, it will be removed (auto-delete queue) */ /* as exchange has no queue bind to it, it will be removed (auto-delete exchange) */