6

在我的api資源管理器中,當向插入一些數據到firebase的端點執行插入操作時,出現以下錯誤。java.lang.IllegalStateException:此功能僅適用於後端實例

503 

- Show headers - 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "backendError", 
    "message": "java.lang.IllegalStateException: This feature is only available to backend instances." 
    } 
    ], 
    "code": 503, 
    "message": "java.lang.IllegalStateException: This feature is only available to backend instances." 
} 
} 

此外,我在端點類內使用以下代碼,其中firebase是靜態對象引用。

FirebaseOptions options = new FirebaseOptions.Builder() 
     .setServiceAccount(servletContext.getResourceAsStream("/WEB-INF/google-services.json")) 
     .setDatabaseUrl("https://contactifyapp.firebaseio.com/") 
     .build(); 

if (firebaseApp == null) 
    firebaseApp = FirebaseApp.initializeApp(options); 

// As an admin, the app has access to read and write all data, regardless of Security Rules 
DatabaseReference ref = FirebaseDatabase 
     .getInstance() 
     .getReference(); 
String data = runMeNow.getData(); 
JSONObject jsonObject = new JSONObject(data); 
Random rand = new Random(); 
ref.child(Keys.CONTACT_INFO).child("child").child(Keys.USER_INFO).setValue(jsonObject.get(Keys.USER_INFO)); 

日誌是如下的服務器:

19:30:43.061 
com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backend method 
java.lang.IllegalStateException: This feature is only available to backend instances. 
    at com.google.appengine.api.system.SystemServiceImpl.translateException(SystemServiceImpl.java:40) 
    at com.google.appengine.api.system.SystemServiceImpl.startBackgroundRequest(SystemServiceImpl.java:28) 
    at com.google.firebase.database.utilities.DefaultRunLoop$FirebaseThreadFactory.newThread(DefaultRunLoop.java:13) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:600) 
    at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943) 
    at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1635) 
    at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:307) 
    at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:526) 
    at com.google.firebase.database.connection.PersistentConnectionImpl.doIdleCheck(PersistentConnectionImpl.java:1098) 
    at com.google.firebase.database.connection.PersistentConnectionImpl.<init>(PersistentConnectionImpl.java:266) 
    at com.google.firebase.database.core.GaePlatform.newPersistentConnection(GaePlatform.java:128) 
    at com.google.firebase.database.core.Context.newPersistentConnection(Context.java:195) 
    at com.google.firebase.database.core.Repo.<init>(Repo.java:64) 
    at com.google.firebase.database.core.RepoManager.createLocalRepo(RepoManager.java:87) 
    at com.google.firebase.database.core.RepoManager.createRepo(RepoManager.java:28) 
    at com.google.firebase.database.FirebaseDatabase.ensureRepo(FirebaseDatabase.java:249) 
    at com.google.firebase.database.FirebaseDatabase.getReference(FirebaseDatabase.java:114) 
    at com.safran.contactify.backend.RunMeNowEndpoint.insert(RunMeNowEndpoint.java:105) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:44) 
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:363) 
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:113) 
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:71) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:439) 
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:446) 
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:256) 
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:310) 
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:302) 
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:443) 
    at java.lang.Thread.run(Thread.java:745) 

回答

15

要使用App Engine的使用火力地堡,就必須使用手動縮放。這是因爲Firebase使用後臺線程來偵聽更改,App Engine只允許手動縮放後端實例上的長期後臺線程。 以下配置添加到您的appengine-web.xml

<manual-scaling> 
    <instances>1</instances> 
</manual-scaling> 
+0

根據這意味着將有隻有一個服務的實例,而不管請求量的文檔。這是否意味着請求將會一個接一個地同步執行,因爲我們的服務只有一個實例? 「無論負載級別如何,帶有手動縮放的服務都會持續運行相同數量的實例,從而允許諸如複雜的初始化和依賴內存狀態的應用程序等任務。」 –

+1

是的,應用程序根本無法擴展。您將獲得一個實例可以處理的一定數量的請求,所有其他請求將在隊列中等待。 – Yevgen

+0

這是怎麼來的文件中沒有提到! :( – Noman