/micronaut-fcm-client

Micronaut Sending Push Notification using Google Firebase Cloud Messaging

Primary LanguageGroovyApache License 2.0Apache-2.0

mn-fcm-client

Micronaut Sending Push Notification (ex. Google Firebase Cloud Messaging)

In this example we want to consume this service : https://firebase.google.com/docs/cloud-messaging/send-message

FCM Setup

  • Go to the Firebase website : https://firebase.google.com/
  • Login using your Google account to access to the Console
  • Add a project (for example "MN-FCM-TEST") to create a new one
  • In the project dashboard, select "project settings" (gear icon in the left menu)
  • Jump to the Cloud Messaging tab and copy the Legacy Server Key to the application.yml as your own SERVER_KEY
  • Remember to configure your app for Android or iOS too

Micronaut Push Service

Test :

$ ./gradlew check
...
BUILD SUCCESSFUL in 0s
4 actionable tasks: 4 up-to-date

Start :

$ ./gradlew run
...
[main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 770ms. Server Running: http://localhost:8080

Request example :

curl -X POST -H "Content-Type: application/json" -d '{
	"to" : "/topics/test",
	"title": "TITLE",
	"body": "BODY",
	"data": 
	{
	  "Key-1": "VALUE 1",
	  "Key-2": "VALUE 2"
	}
}' 
http://localhost:8080/msg/push

Response :

{
    "message_id": "5548062101043273972"
}