반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Maven
- Java
- Tomcat
- config
- spring3
- FCM
- yona
- ajax
- PM2
- security
- NextJS
- javascript
- nodejs
- mybatis
- pwa
- node.js
- SpringBoot
- popup
- jquery
- Eclipse
- docker
- jenkins
- git
- Next.js
- mysql
- Push
- rocky9
- centos7
- MariaDB
- MSsql
Archives
- Today
- Total
ふたりで
initialize multiple firebase adminSDK in SpringBoot 본문
728x90
반응형
SMALL
여러앱에 알림 메시지 전송을 중앙 집중형으로 관리할 때 참고.
1. firebase admin SDK Maven 설정.
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>9.4.2</version>
</dependency>
2. firebase admin SDK 초기화 로직.
/**
* @param appName
* @param credentialsPath
*/
private void initializeFirebaseApp(String appName, String credentialsPath) {
try {
// 자격 증명 파일을 읽어옵니다.
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(new ClassPathResource(credentialsPath).getInputStream()))
.build();
// Firebase 앱이 존재하지 않거나 특정 이름의 앱 인스턴스가 없는 경우, 앱을 초기화합니다.
boolean appExists = false;
for (FirebaseApp app : FirebaseApp.getApps()) {
if (app.getName().equals(appName)) {
appExists = true;
break;
}
}
if (!appExists) {
FirebaseApp.initializeApp(options, appName);
System.out.println("Firebase App '" + appName + "' initialized successfully.");
} else {
System.out.println("Firebase App '" + appName + "' already exists, skipping initialization.");
}
} catch (IOException e) {
System.err.println("Error initializing Firebase App '" + appName + "': " + e.getMessage());
}
}
반응형
728x90
SMALL
3. firebase admin SDK 초기화 함수 호출.
@PostConstruct
public void initializeFirebaseApps() {
initializeFirebaseApp(AAA_APP_NAME, "aaafcm/aaa-firebase-adminsdk-fmagz-3xxxxxx.json");
initializeFirebaseApp(BBB_APP_NAME, "bbbfcm/bbb-firebase-adminsdk-uz4k8-aXXXXXX.json");
}
# 참고 자료 출처:
https://firebase.google.com/docs/admin/setup?hl=ko#windows
서버에 Firebase Admin SDK 추가
Admin SDK는 권한이 있는 환경에서 Firebase와 상호작용할 수 있는 서버 라이브러리 집합입니다.
firebase.google.com
728x90
반응형
LIST
Comments