pub struct MessagingClient { /* private fields */ }Expand description
Firebase Cloud Messaging client.
Unlike crate::auth::AuthClient, there is no unauthenticated emulator
mode: every FCM v1 and Instance ID call requires a live OAuth2 bearer
token. Build one with MessagingClientBuilder.
Implementations§
Source§impl MessagingClient
impl MessagingClient
Sourcepub fn builder(project_id: impl Into<String>) -> MessagingClientBuilder
pub fn builder(project_id: impl Into<String>) -> MessagingClientBuilder
Starts building a new client for the given Firebase project.
Sourcepub async fn send(
&self,
message: &Message,
dry_run: bool,
) -> Result<String, MessagingError>
pub async fn send( &self, message: &Message, dry_run: bool, ) -> Result<String, MessagingError>
Sends a single message, returning FCM’s assigned message id.
When dry_run is true, the message is validated but not actually
delivered (FCM v1’s validate_only).
Sourcepub async fn send_each(
&self,
messages: &[Message],
dry_run: bool,
) -> Result<BatchResponse, MessagingError>
pub async fn send_each( &self, messages: &[Message], dry_run: bool, ) -> Result<BatchResponse, MessagingError>
Sends up to MAX_BATCH_SIZE messages, returning a per-message
success/failure result. Each message is sent as its own HTTP
request, concurrently — mirroring the official Admin SDKs’
sendEach/sendEachForMulticast, which dispatch every request
before awaiting any of them (Promise.allSettled) rather than
serializing round-trips. A failure sending one message does not
prevent the others from being sent.
Sourcepub async fn send_each_for_multicast(
&self,
message_template: &Message,
tokens: &[String],
dry_run: bool,
) -> Result<BatchResponse, MessagingError>
pub async fn send_each_for_multicast( &self, message_template: &Message, tokens: &[String], dry_run: bool, ) -> Result<BatchResponse, MessagingError>
Sends one message to up to MAX_BATCH_SIZE device registration
tokens, individually. Equivalent to building one Message per
token from a shared template and calling Self::send_each.
Sourcepub async fn subscribe_to_topic(
&self,
tokens: &[String],
topic: &str,
) -> Result<TopicManagementResponse, MessagingError>
pub async fn subscribe_to_topic( &self, tokens: &[String], topic: &str, ) -> Result<TopicManagementResponse, MessagingError>
Subscribes device registration tokens to a topic.
A single call can partially fail: see TopicManagementResponse.
Sourcepub async fn unsubscribe_from_topic(
&self,
tokens: &[String],
topic: &str,
) -> Result<TopicManagementResponse, MessagingError>
pub async fn unsubscribe_from_topic( &self, tokens: &[String], topic: &str, ) -> Result<TopicManagementResponse, MessagingError>
Unsubscribes device registration tokens from a topic.
A single call can partially fail: see TopicManagementResponse.
Sourcepub fn legacy_http_transport_enabled(&self) -> bool
pub fn legacy_http_transport_enabled(&self) -> bool
Whether Self::send_each/Self::send_each_for_multicast were
configured (via MessagingClientBuilder::enable_legacy_http_transport)
to send each message over its own HTTP/1.1 request instead of
multiplexing over HTTP/2.
This crate’s HTTP client (reqwest over hyper) negotiates HTTP/2
automatically when the server supports it and otherwise falls back to
HTTP/1.1, so this flag is a no-op today; it exists so callers
migrating from the official Admin SDKs (where this setting works
around a legacy Node.js HTTP/2 bug) have an equivalent method to call
without their code failing to compile.