티스토리 뷰

개발

apns pushy 라이브러리 이슈

달리는개발자 2020. 10. 7. 22:33

apple push notification service를 사용 중 문제가 발생했습니다.

github.com/jchambers/pushy pushy 라는 오픈소스를 사용하고 있는데 갑자기 아래 코드에서 경과시간이 오래걸리더군요

final PushNotificationResponse<SimpleApnsPushNotification> response =
                        sendNotificationFuture.get();

if (response.isAccepted()) {
  log.warn("Push notification accepted by APNs gateway.");
} else {
  log.info("Notification rejected by the APNs gateway: {}", response.getRejectionReason());

  if (response.getTokenInvalidationTimestamp() != null) {
    log.info("	…and the token is invalid as of  {}", response.getRejectionReason());
  }
}

StopWatch '': running time (millis) = 6072170

600초도 아니고 6072초.......ㅡㅡ;;;;;;;

ThreadPool을 써서 비동기로 처리되어 있었는데 모든 Thread에서 대기가 걸려서 그 다음 작업이 처리 되지 않았습니다.

iOS 푸시가 보내지지 않는 장애가 발생했고요

 

급하게 pushy 버전을 0.13.9에서 0.14.1로 변경했습니다. groupId가 변경됐으니 꼭 확인해 보세요

pushy 0.13.9

<dependency>
    <groupId>com.turo</groupId>
    <artifactId>pushy</artifactId>
    <version>0.13.9</version>
</dependency>

 
pushy 0.14.1

<dependency>
    <groupId>com.eatthepath</groupId>
    <artifactId>pushy</artifactId>
    <version>0.14.1</version>
</dependency>

 

버전 업그레이드를 진행하면서 아래 예제와 같이 block 처리되는 부분을 변경했습니다.

for (final ApnsPushNotification pushNotification : collectionOfPushNotifications) {
    final CompletableFuture sendNotificationFuture = apnsClient.sendNotification(pushNotification);

    // This call will block until we get a reply from the server
    final PushNotificationResponse response = sendNotificationFuture.get();
}

|- 40ms -||- 40ms -| ... |- 40ms -||- 40ms -|

위와 같이 응답이 올 때까지 대기하고 그 다음 처리는 계속 지연될 수밖에 없습니다.

꼭 아래와 같이 콜백으로 처리해 주세요~!!

for (final ApnsPushNotification pushNotification : collectionOfPushNotifications) {
    final CompletableFuture sendNotificationFuture = apnsClient.sendNotification(pushNotification);

    sendNotificationFuture.whenComplete((response, cause) -> {
        // This will get called when the sever has replied. response will
        // be null and cause will be non-null if something went wrong when
        // sending the notification.
        
        log.error("ios error - {}", cause.getMessage());
    });
}

|---------- 40ms ----------|

   |---------- 40ms ----------|

      |---------- 40ms ----------|

         |---------- 40ms ----------|

            |---------- 40ms ----------|

 

위와 같이 코드를 변경하고 로그를 확인하니 아래와 같은 오류가 찍히네요.....ㅠㅠ

APNS 인증서가 만료되었습니다. 푸시 서버를 만들어 본 경험이 없어서 이런 경우가 있네요

javax.net.ssl.SSLException: Received fatal alert: certificate_expire

 

급하게 인증서 교체 후 처리됐습니다.

덕북에 문제가 되었던 동기처리 부분을 비동기로 변경할 수 있었으나 우리나라 사용자 특성상 iOS는 어딜가나 사용자가 많지 않네요

 

pushy 라이브러리 사용하실 때 꼭 아래의 best practice를 확인하세요

github.com/jchambers/pushy/wiki/Best-practices

 

jchambers/pushy

A Java library for sending APNs (iOS/macOS/Safari) push notifications - jchambers/pushy

github.com

 

그리고 요즘엔 FCM으로 APN이 됩니다.

firebase.google.com/docs/cloud-messaging/ios/certs?hl=ko

 

FCM에서 APN 구성  |  Firebase

Firebase 클라우드 메시징 APN 인터페이스는 Apple 푸시 알림 서비스(APN)를 사용하여 백그라운드 상태인 앱을 포함한 iOS 앱으로 최대 4KB의 메시지를 보냅니다. APN을 통해 푸시 알림을 보내려면 다음��

firebase.google.com

 

참 배울게 많은 직업입니다 ^^ 좋은건지 ㅋㅋ

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함