1
我一直在尋找一些類似的問題,但據我所知他們都不是Java相關的。 我想調用一個AWS lambda函數,在其中連接到Firebase數據庫。問題是,處理程序在我從Firebase獲取所需數據之前執行。如何等待AWS lambda中的(Firebase)回調?
@Override
public String handleRequest(Request input, Context context) {
try {
FileInputStream serviceAccountInputStream = new FileInputStream(FIREBASE_SERVICE_ACCOUNT_CREDENTIALS_PATH);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccountInputStream))
.setDatabaseUrl(FIREBASE_DATABASE_URL)
.build();
FirebaseApp.initializeApp(options);
DatabaseReference ref = FirebaseDatabase
.getInstance()
.getReference("users/" + input.getUid());
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.print(dataSnapshot);
// TODO: Do computations on data and return results
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.print("Canceled");
// TODO: Return error
}
});
} catch (Exception e) {
e.printStackTrace();
}
// TODO: Return computed results
return "This could be the start of something new.";
}
我需要從火力地堡數據庫中讀取數據,做一些計算與它的計算結果返回給用戶。我怎樣才能做到這一點? :)