Search code examples
firebasefirebase-authenticationfirebase-cloud-messagingfirebase-notificationsfirebase-admin

Send push notifications with Firebase Messaging from several servers


I have server application which is sending push notification using Firebase Messaging. I have Firebase service account for that. Code is very simple and looks like the following:

FirebaseOptions options = new FirebaseOptions.Builder()
        .setCredentials(credentials)
        .build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(options);
firebaseMessaging = FirebaseMessaging.getInstance(firebaseApp);

and sending like:

String messageId = firebaseMessaging.send(...);

I am using firebase-admin-sdk I have several servers with this application and all of them will send push notification. The question is

  1. Can I use the same service account from several servers simultaneously?
  2. Are there any limitations/quotas for service accounts in Firebase Messaging(how many IP addresses can use it, how many requests per IP or per account, etc.)?
  3. Can I use JWT to send push notifications from servers?

Solution

    1. Yes, you can. As long as each server is able to generate an access token you should be fine. See sample

    2. No, there are no limitations on FCM. FCM can be limited if abuse is discovered. From the documentation:

    Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

    1. No, FCM Auth only supports OAuth 2.0 Access Tokens. FCM Legacy API supports an API key which is available from the Firebase console.