🛠️Backend/오류해결

[Firebase] Requested entity was not found.

뉴발자 2024. 11. 12. 19:08
728x90

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

개요

기존 로직에서 Firebase의 전체 알림을 sendEachForMulticast() 함수로 전송하고 있었다.

 

하지만 사용자 별로 데이터를 다르게 전송해줘야 하는 상황이 생겨서 send() 함수로 메시지 객체를 전송했다.

 

해당 코드를 수정한 후 알림을 전송했을 때 'Requested entity was not found' 에러가 발생했다.

 

 

원인

발생한 에러 메시지는 아래와 같았다.

Requested entity was not found.

 

해당 에러의 발생 원인은

  • 사용자가 해당 앱을 삭제했을 때
  • 사용자가 앱의 FCM 푸시 알림을 비활성화 했을 때
  • FCM 서버에서 디바이스 등록을 해제했을 때
  • 디바이스와 FCM 서버의 연결이 끊겼을 때

위 4가지 원인이 있었다.

 

필자의 경우 이전에 테스트했던 앱을 삭제하면서 해당 에러가 발생했다.

 

 

해결

기존의 코드에서는 for() 문과 send() 함수를 사용하여 생성한 Message 객체를 전송했다.

for (int i = 0; users.size(); i++) {
	Message msg = Message.builder()
    	.setNotification(Notification.builder()
        	.setTitle(title)
            .setBody(body)
            .build))
        .setToken(token)
        .putAllData(data)
    	.build();
        
    try {
        FirebaseMessaging.getInstance().send(message);
    } catch (FirebaseMessagingException e) {
        throw new FirebaseException(e.getErrorCode(), e.getMessage(), e.getCause());
    }
    
}

 

변경된 코드에서는 Message 객체를 List에 담아서 sendEach() 함수로 한 번에 전송했다.

List<Message> msgs = users.entrySet().stream().map(
    entry -> Message.builder()
        .setNotification(Notification.builder()
            .setTitle(title)
            .setBody(body)
            .build))
        .setToken(entry.token)
        .putAllData(entry.data)
        .build()
    ).collect(Collectors.toList());

try {
    FirebaseMessaging.getInstance().sendEach(messages);
} catch (FirebaseMessagingException e) {
    throw new FirebaseException(e.getErrorCode(), e.getMessage(), e.getCause());
}

 

 

참고 사이트

https://www.omnibuscode.com/board/board_pwa/59166

 

OMNIBUSCODE [PWA] - FirebaseMessagingException: Requested entity was not found.

얼마전부터 콘솔에서 다음과 같은 에러 메세지가 출력되기 시작했다. com.google.firebase.messaging.FirebaseMessagingException: Requested entity was not found. at com.google.firebase.messaging.FirebaseMessagingException.withMessaging

www.omnibuscode.com

 

 

 

 

 

 

 

 

 

 

728x90