问题
I've never used Google App Engine backends and I'm very confused by lack of samples and detailed documentation.
Let's say I have a voting app. I want to collect votes in regular stateless GAE servlet and then pass the data to backend instance that is resident and it processes my data. How can I pass data from regular servlet to backend servlet ? How do I assign what servlet class is normal servlet and what servlet should be handled only in backend instance? I don't see how I can assign servlet to backend in config xml.
Or what if I have two backends - class B1 and class B2. How can I choose in code of stateless servlet what backends are active right now? I heard that I should use URL Fetch to talk to backends but how ? I didn't find how I can iterate through backend instances.
Please advise :)
回答1:
You should start by reading the documentation on backends
How can I pass data from regular servlet to backend servlet ?
You have a few options - pass it indirectly by sticking data in memcache or the datastore. Or pass it directly by using URLFetch to make requests to your backends (see addressing info below)
How do I assign what servlet class is normal servlet and what servlet should be handled only in backend instance?
The doc on Backend Configuration explains that you can't do that (yet), though you can mark them as admin only so they are not available to the public:
Backends share the set of servlets defined in web.xml with your main application version. It is not possible at the moment to configure a separate set of servlets for each backend.
The "Addressing Backends" section includes info on how to connect to a specific backend:
A backend instance can be targeted with HTTP requests to http://[instance].[backend].[app].appspot.com, or at your application's custom domain. If you target a backend without targeting an instance using http://[backend].[app].appspot.com, App Engine selects the first available instance of the backend.
When you configure your backends , you give them names, which go into the [backend] slot in the url scheme described above. If you wanted to send a http request to the first available B1 instance, you would use something like http://B1.ruslansapp.appspot.com/dosomething/
来源:https://stackoverflow.com/questions/7923129/how-to-pass-data-from-regular-stateless-servlet-to-backend-instance