ข้อความตามหัวข้อใน Flutter
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การรับส่งข้อความตามหัวข้อของ FCM ช่วยให้คุณส่งข้อความไปยังอุปกรณ์หลายเครื่องที่เลือกใช้หัวข้อหนึ่งๆ ได้ โดยอิงตามรูปแบบการเผยแพร่/การสมัครรับข้อมูล คุณเขียนข้อความหัวข้อตามต้องการ และ FCM จะจัดการการกำหนดเส้นทางและส่งข้อความไปยังอุปกรณ์ที่ถูกต้องอย่างน่าเชื่อถือ
ตัวอย่างเช่น ผู้ใช้แอปพยากรณ์น้ำขึ้นน้ำลงในพื้นที่อาจเลือกใช้หัวข้อ "การแจ้งเตือนกระแสน้ำ" และรับการแจ้งเตือนเกี่ยวกับสภาพแวดล้อมที่เหมาะสมสำหรับการตกปลาในน้ำเค็มในพื้นที่ที่ระบุ ผู้ใช้แอปกีฬาสามารถสมัครรับข้อมูลอัปเดตคะแนนการแข่งขันแบบสดของทีมโปรดได้โดยอัตโนมัติ
โปรดคำนึงถึงสิ่งต่อไปนี้เกี่ยวกับหัวข้อ
การรับส่งข้อความตามหัวข้อเหมาะกับเนื้อหา เช่น สภาพอากาศ หรือข้อมูลอื่นๆ ที่เปิดเผยต่อสาธารณะ
มากที่สุด
ข้อความหัวข้อได้รับการเพิ่มประสิทธิภาพเพื่ออัตราการรับส่งมากกว่าเวลาในการตอบสนอง หากต้องการส่งข้อความไปยังอุปกรณ์เครื่องเดียวหรือกลุ่มอุปกรณ์ขนาดเล็กอย่างรวดเร็วและปลอดภัย
ให้กำหนดเป้าหมายข้อความไปยังโทเค็นการลงทะเบียน
ไม่ใช่หัวข้อ
หากต้องการส่งข้อความไปยังอุปกรณ์หลายเครื่องต่อผู้ใช้ ให้พิจารณา
การรับส่งข้อความกลุ่มอุปกรณ์
สำหรับกรณีการใช้งานเหล่านั้น
การรับส่งข้อความตามหัวข้อรองรับการติดตามแต่ละหัวข้อได้ไม่จำกัด อย่างไรก็ตาม FCM
จะบังคับใช้ขีดจำกัดในด้านต่อไปนี้
- อินสแตนซ์แอป 1 รายการจะติดตามหัวข้อได้ไม่เกิน 2,000 หัวข้อ
- หากคุณใช้การนำเข้าแบบเป็นชุด
เพื่อสมัครใช้บริการอินสแตนซ์ของแอป คำขอแต่ละรายการจะจำกัดไว้ที่อินสแตนซ์ของแอป 1, 000 รายการ
- ระบบจะจำกัดอัตราความถี่ของการสมัครใช้บริการใหม่ต่อโปรเจ็กต์ หากคุณส่งคำขอสมัครรับข้อมูลมากเกินไปในช่วงเวลาสั้นๆ เซิร์ฟเวอร์ FCM จะตอบกลับด้วยการตอบกลับ
429 RESOURCE_EXHAUSTED
("โควต้าเกิน") ลองอีกครั้ง
โดยใช้ Exponential Backoff
สมัครใช้บริการแอปไคลเอ็นต์ไปยังหัวข้อ
แอปไคลเอ็นต์สามารถติดตามหัวข้อที่มีอยู่ หรือสร้างหัวข้อใหม่ได้ เมื่อแอปไคลเอ็นต์สมัครรับข้อมูลชื่อหัวข้อใหม่ (ชื่อที่ยังไม่มีในโปรเจ็กต์ Firebase) ระบบจะสร้างหัวข้อใหม่ที่มีชื่อนั้นใน FCM และไคลเอ็นต์ใดก็ได้จะสมัครรับข้อมูลหัวข้อนั้นได้ในภายหลัง
หากต้องการสมัครรับข้อมูลหัวข้อ ให้เรียกใช้ subscribeToTopic()
พร้อมชื่อหัวข้อ เมธอดนี้
จะแสดงผล Future
ซึ่งจะได้รับการแก้ไขเมื่อการสมัครใช้บริการสำเร็จ
await FirebaseMessaging.instance.subscribeToTopic("topic");
หากต้องการยกเลิกการติดตาม ให้โทรหา unsubscribeFromTopic()
พร้อมระบุชื่อหัวข้อ
ไม่รองรับ subscribeToTopic()
และ unsubscribeFromTopic()
สำหรับไคลเอ็นต์บนเว็บ ดูวิธีจัดการการติดตามสำหรับผู้ใช้เว็บได้ที่
ส่งข้อความไปยังหัวข้อในเว็บ/JavaScript
ขั้นตอนถัดไป
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-16 UTC
[null,null,["อัปเดตล่าสุด 2025-08-16 UTC"],[],[],null,["# Topic messaging on Flutter\n\n\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-----------------------------------\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\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)."]]