6

I'm using multiple modules with Google AppEngine and was wondering if its possible to run development server (java version) so that ports that are assigned to different modules are always the same? At the moment they seem to be random. Can I decide on those ports? I would like to be able to establish communication with between modules in a sustainable way (from the development perspective). At the moment if we have two modules, let's call them A and B, and we would like to consume services exposed by module A in module B there's no easy way to know which URL to hit from module B.

markovuksanovic
  • 15,676
  • 13
  • 46
  • 57

4 Answers4

8

It is possible to set the port of each module using JVM parameters.

-Dcom.google.appengine.devappserver_module.{module_name}.port=8081

I use the appengine-maven-plugin with the following configuration (my bespoke module is called "analysis"):

<plugin>
   <groupId>com.google.appengine</groupId>
   <artifactId>appengine-maven-plugin</artifactId>
   <configuration>
      <jvmFlags>
         <jvmFlag>-Ddatastore.backing_store=${project.basedir}/target/local_db.bin</jvmFlag>
         <jvmFlag>-Xdebug</jvmFlag>
         <jvmFlag>-Dcom.google.appengine.devappserver_module.analysis.port=8081</jvmFlag>
         <jvmFlag>-XX:MaxPermSize=512m</jvmFlag>
         <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8001,server=y,suspend=n</jvmFlag>
      </jvmFlags>
      <enhancerApi>JPA</enhancerApi>
      <fullScanSeconds>2</fullScanSeconds>
   </configuration>
</plugin>

When I run the mvn appengine:devserver then the logs corresponding to that module are like this:

[INFO] INFO: Started SelectChannelConnector@127.0.0.1:8081
[INFO] Jun 10, 2014 10:44:16 AM com.google.appengine.tools.development.JettyContainerService startHotDeployScanner
[INFO] INFO: Full scan of the web app in place every 2s.
[INFO] Jun 10, 2014 10:44:16 AM com.google.appengine.tools.development.AbstractModule startup
[INFO] INFO: Module instance analysis is running at http://localhost:8081/
[INFO] Jun 10, 2014 10:44:16 AM com.google.appengine.tools.development.AbstractModule startup
[INFO] INFO: The admin console is running at http://localhost:8081/_ah/admin
[INFO] Jun 10, 2014 11:44:16 AM com.google.appengine.tools.development.DevAppServerImpl doStart
[INFO] INFO: Dev App Server is now running

I hope it helped.

nomukaiki
  • 81
  • 1
  • 2
2

You can set a module's port via a system property in the module's appengine-web.xml file. For example:

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <module>MY_MODULE</module>
    <version>v1</version>
    <threadsafe>true</threadsafe>
    <system-properties>
        <property name="com.google.appengine.devappserver_module.MY_MODULE.port"
            value="8081"/>
    </system-properties>
</appengine-web-app>
Bob Lee
  • 1,962
  • 1
  • 12
  • 9
1

I don't think Google will provide any easy approach to this problem. You'll have to use the modules service and wrap it to your helper class such as LinkFactory with methods like getLinkToA(String) and getLinkToB(String) and you them everywhere you're creating the links to the modules.

Same (and bigger) problem is if you use the dispatch file. This is actually bigger problem, because parts of your front end app may failed since the routing is not working in the development server.

musketyr
  • 808
  • 5
  • 16
-2

Although the modules service could be useful in this scenario, and I believe it would work, I solve the problem in a bit different way.

I modified my build script to run all the modules on localhost, but on different port (essentially there are a few local appengine instances running). The configuration information (IP:PORT) is stored in a configuration file and is easily accessible to any module. For the deployment I still package the application into an ear archive.

antony.trupe
  • 10,640
  • 10
  • 57
  • 84
markovuksanovic
  • 15,676
  • 13
  • 46
  • 57
  • Can you share your config settings? – Ivan Cachicatari May 29 '14 at 21:18
  • 2
    This is not a useful answer as it is recommending an approach wholly different from established practices and Google's own documentation. The best answer is nomukaiki's as that is exactly how the official Google sample apps do it. – Jacob Fike May 21 '15 at 22:54