Flutter에서 주제 메시징
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
FCM 주제 메시징은 게시/구독 모델을 기반으로 특정 주제를 구독하는 여러 기기에 메시지를 보내 줍니다. 필요에 따라 주제 메시지를 작성하면 FCM에서 라우팅을 처리하여 올바른 기기에 정확히 전송합니다.
예를 들어 지역 조수 예보 앱 사용자는 '조류 특보' 주제를 수신 동의하여 해당 지역에서 바다낚시에 최적인 상태에 대한 알림을 수신할 수 있습니다. 스포츠 앱 사용자는 응원하는 팀의 경기 실황 자동 업데이트를 구독할 수 있습니다.
주제와 관련된 주의사항은 다음과 같습니다.
주제 메시징은 날씨 등 공개적으로 제공되는 정보에 가장 적합합니다.
주제 메시지는 지연 시간이 아닌 처리량에 맞게 최적화되어 있습니다. 기기 한 대나 적은 수의 기기에 빠르고 안전하게 전송하려면 주제가 아닌 등록 토큰으로 메시지를 타겟팅하세요.
사용자를 기준으로 여러 기기에 메시지를 보내야 하는 경우 기기 그룹 메시징을 사용하는 것이 좋습니다.
주제 메시징에서 각 주제에 지원하는 구독에는 제한이 없습니다. 그러나 FCM은 다음 영역에 제한을 두고 있습니다.
- 하나의 앱 인스턴스는 최대 2,000개까지 주제를 구독할 수 있습니다.
- 일괄 가져오기를 사용하여 앱 인스턴스를 구독하는 경우 각 요청은 1,000개의 앱 인스턴스로 제한됩니다.
- 새 구독의 빈도는 프로젝트별로 비율이 제한됩니다. 단기간에 지나치게 많은 구독 요청을 보내는 경우 FCM 서버는
429 RESOURCE_EXHAUSTED
('할당량 초과') 응답을 보냅니다. 지수 백오프로 다시 시도하세요.
클라이언트 앱에서 주제 구독
클라이언트 앱에서 기존 주제를 구독하거나 새 주제를 만들 수 있습니다. 클라이언트 앱에서 Firebase 프로젝트에 아직 없는 새 주제 이름을 구독하면 FCM에 이 이름으로 새 주제가 생성되고 이후에 다른 클라이언트에서 이 주제를 구독할 수 있습니다.
주제를 구독하려면 주제 이름과 함께 subscribeToTopic()
을 호출합니다. 이 메서드는 구독이 성공하면 확인되는 Future
를 반환합니다.
await FirebaseMessaging.instance.subscribeToTopic("topic");
구독을 취소하려면 주제 이름과 함께 unsubscribeFromTopic()
을 호출합니다.
subscribeToTopic()
및 unsubscribeFromTopic()
은 웹 클라이언트에서 지원되지 않습니다. 웹 사용자의 구독을 관리하는 방법을 알아보려면 웹/JavaScript에서 주제로 메시지 보내기를 참고하세요.
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-16(UTC)
[null,null,["최종 업데이트: 2025-08-16(UTC)"],[],[],null,["\u003cbr /\u003e\n\nBased on the publish/subscribe model, FCM topic messaging allows you to send a message\nto multiple devices that have opted in to a particular topic. You compose topic messages as\nneeded, and FCM handles routing and delivering the message reliably to the right\ndevices.\n\nFor example, users of a local tide\nforecasting app could opt in to a \"tidal currents alerts\" topic and receive\nnotifications of optimal saltwater fishing conditions in specified areas. Users of a sports app\ncould subscribe to automatic updates in live game scores for their favorite\nteams.\n\nSome things to keep in mind about topics:\n\n- Topic messaging is best suited for content such as weather, or other publicly\n available information.\n\n- Topic messages are **optimized for throughput rather than latency** . For fast,\n secure delivery to single devices or small groups of devices,\n [target messages to registration tokens](/docs/cloud-messaging/send-message#send_messages_to_specific_devices),\n not topics.\n\n- If you need to send messages to multiple devices *per user* , consider\n [device group messaging](/docs/cloud-messaging/send-message#send_messages_to_device_groups)\n for those use cases.\n\n- Topic messaging supports unlimited subscriptions for each topic. However, FCM\n enforces limits in these areas:\n\n - One app instance can be subscribed to no more than 2000 topics.\n - If you are using [batch import](https://developers.google.com/instance-id/reference/server#manage_relationship_maps_for_multiple_app_instances) to subscribe app instances, each request is limited to 1000 app instances.\n - The frequency of new subscriptions is rate-limited per project. If you send too many subscription requests in a short period of time, FCM servers will respond with a `429 RESOURCE_EXHAUSTED` (\"quota exceeded\") response. Retry with exponential backoff.\n\nSubscribe the client app to a topic\n\nClient apps can subscribe to any existing topic, or they can create a new\ntopic. When a client app subscribes to a new topic name (one that does\nnot already exist for your Firebase project), a new topic of that name is\ncreated in FCM and any client can subsequently subscribe to it.\n\nTo subscribe to a topic, call `subscribeToTopic()` with the topic name. This method\nreturns a `Future`, which resolves when the subscription succeeded: \n\n await FirebaseMessaging.instance.subscribeToTopic(\"topic\");\n\nTo unsubscribe, call `unsubscribeFromTopic()` with the topic name.\n\n`subscribeToTopic()` and `unsubscribeFromTopic()` are not supported for web\nclients. To learn how to manage subscriptions for web users, see\n[Send messages to topics on Web/JavaScript](https://firebase.google.com/docs/cloud-messaging/js/topic-messaging).\n\nNext steps\n\n- Learn how to [send topic messages](/docs/cloud-messaging/send-message#send-messages-to-topics).\n- Learn how to [Manage topic subscriptions on the server](/docs/cloud-messaging/manage-topics)."]]