Demo app with REST API

1,561 views
Skip to first unread message

Ying-Yi Huang

unread,
Apr 9, 2013, 5:55:02 PM4/9/13
to eureka_...@googlegroups.com
Looking at the demo application, I am wondering if it can be implemented with REST api.  I don't see clear correlation of REST APIs and the Java client lib.   What would be the appID and instanceID in this case?


Karthikeyan Ranganathan

unread,
Apr 9, 2013, 7:10:13 PM4/9/13
to eureka_...@googlegroups.com
Sure- it can be. Since, the communication can use any protocol and eureka just finds those instances for you to talk to to- I thought it will be easier to demonstrate with a low-level socket communication between client and the service.

1) Application ID is the just a way to identify the name of the application- for eg. accountingservice. It is normally not used in communication just for identification in eureka.
2) Instance ID is AWS specific that identifies the name of the instance of an application uniquely  for e.g. i-134ocde. In non-AWS data center it is the same as the hostname (i.e.) acct01, acct02 etc
3) Normally you communicate using the hostname (in AWS that is the public hostname), but in other data centers that is just a well know DNS name to identify the instance (i.e.) acct01, acct02 etc
4) To find your service,  you normally use a virtualHostName (or a vipAddress) similar to how normally use it with a load balancer (i.e.) accountingservice.mycompany.com

You can see this in action in the demo app.

 InstanceInfo nextServerInfo = DiscoveryManager.getInstance()
                .getDiscoveryClient()
                .getNextServerFromEureka(vipAddress, false);
<<<< Discover one instance using VIPAddress

        Socket s = new Socket();
        int serverPort = nextServerInfo.getPort();
        try {
            s.connect(new InetSocketAddress(nextServerInfo.getHostName(),
                    serverPort));
<<< Connect using the hostname to that instance
        } catch (IOException e) {
            System.err.println("Could not connect to the server :"
                    + nextServerInfo.getHostName() + " at port " + serverPort);
        }





On Tue, Apr 9, 2013 at 2:55 PM, Ying-Yi Huang <yingyi...@gmail.com> wrote:
Looking at the demo application, I am wondering if it can be implemented with REST api.  I don't see clear correlation of REST APIs and the Java client lib.   What would be the appID and instanceID in this case?


--
You received this message because you are subscribed to the Google Groups "eureka_netflix" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eureka_netfli...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ying-Yi Huang

unread,
Apr 9, 2013, 8:08:19 PM4/9/13
to eureka_...@googlegroups.com
Thanks Karthik the detail explanation.  For service provider like SampleEurekaService, how does it register with Eureka server? Is this done through the process of the property file? It is not obvious from SampleEurekaService.java.  Also the server port should be obtained from the property file, where does port 8010 come from?

ServerSocket serverSocket = new ServerSocket(configInstance
                    .getIntProperty("eureka.port", 8010).get());



Karthikeyan Ranganathan

unread,
Apr 10, 2013, 1:24:10 PM4/10/13
to eureka_...@googlegroups.com
Ying,


The details about the demo configurations are documented here - https://github.com/Netflix/eureka/wiki/Running-the-Demo-Application.

ServerSocket serverSocket = new ServerSocket(configInstance
                    .getIntProperty("eureka.port", 8010).get());


The above code just gets the property from the property file and if it does exist defaults to 8010.




Ying-Yi Huang

unread,
Apr 11, 2013, 6:15:13 PM4/11/13
to eureka_...@googlegroups.com
Hi Kathik,
In sample-eureka-service.properties file,

eureka.name=sampleservice
eureka.serviceUrl.default=http://localhost/eureka/v2/

Is the serviceUrl the URL that the service registers with Eureka? If yes, with REST API  "curl http://localhost/eureka/v2/apps/sampleservice" should return a list of hostnames that providing sample service.  Once I started the demo service with "runservice.sh",  which REST API calls I could run to exam the Eureka registry?

Thanks,
Ying-Yi

Ying-Yi Huang

unread,
Apr 11, 2013, 7:50:37 PM4/11/13
to eureka_...@googlegroups.com
Hi Kathik,

My eureka server is running at http://localhost:<port>/eureka.  If I want to use REST API to register my service, what would be the URL to post? Since "/eureka/v2/...."  doesn't exist, "POST /eureka/v2/apps/appID"  failed. How's the URL constructed?

Thanks,
Ying-Yi

Nitesh Kant

unread,
Apr 12, 2013, 12:24:52 AM4/12/13
to eureka_...@googlegroups.com
Eureka's wiki, specifically, this page: https://github.com/Netflix/eureka/wiki/Eureka-REST-operations has details about the REST API.
That should help you get started.

Karthikeyan Ranganathan

unread,
Apr 12, 2013, 1:23:24 AM4/12/13
to eureka_...@googlegroups.com
Thanks Nitesh. 

Ying,

If you are using the REST API, are you sending the XML/JSON as the document suggests?

Thanks.

Ying-Yi Huang

unread,
Apr 12, 2013, 2:50:11 PM4/12/13
to eureka_...@googlegroups.com
I'd like to implement the demo app in Python with REST API.  First I start the eureka server in Tomcat at http://lxdm123m7:8080/eureka/.

Here are the steps the sample service:

1. Register with Eureka
curl -X POST /eureka/v2/apps/sampleservice with data. Note: Post failed with 404. Is there anything I need to do before POST?

<instance>
 <hostName>lxdm123m7</hostName>
 <app>sampleservice</app>
 <ipAddr></ipAddr>
 <vipAddr>sampleservice.mydomain.net</vipAddr>
 <secureVipAddress>sampleservice.mydomain.net</secureVipAddress>
 <status>UP</status>
 <port>8080</port>
 <securePort>8080</securePort>
 <dataCenterInfo>
  <name>MyOwn</name>
 </dataCenterInfo>
</instance>

2. Looping to wait for coming requests. Question: does the service need to send heartbeat manually every 30 seconds? ( PUT /eureka/v2/apps/sampleservice/lxdm123m7)

3. Un-register the service with Eureka

DELETE /eureka/v2/apps/sampleservice/lxdm123m7

Steps for sample service client:
1. Find all the instances providing sampleservice

GET /eureka/v2/apps/sampleservice

2. Does the client pick on itself from the list returned? How the round-robin works here?

3. Connect to the host and port of the service

Please advise anything I missed here.
Ying-Yi
To unsubscribe from this group and stop receiving emails from it, send an email to eureka_netflix+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Karthikeyan Ranganathan

unread,
Apr 12, 2013, 3:50:42 PM4/12/13
to eureka_...@googlegroups.com
Can you send me all your configuration properties files before I could advise?

Thanks.

Karthikeyan Ranganathan

unread,
Apr 12, 2013, 3:58:09 PM4/12/13
to eureka_...@googlegroups.com
Also, I'm wondering what your context path of your web application is? Are you able to get to the eureka status page.

http://<your_hostname>:<post>/<context>

Ying-Yi Huang

unread,
Apr 12, 2013, 4:20:43 PM4/12/13
to eureka_...@googlegroups.com
I am able to access the status page at http://lxdm123m7.etrade.com:8080/eureka/.  I attached the screenshot. At the page, the URL is

registered-replicas  
http://localhost/eureka/v2/


Should it be http://lxdm123m7.etrade.com:8080/eureka/v2?  How do I change that?

Thanks,
Ying-Yi

Karthikeyan Ranganathan

unread,
Apr 12, 2013, 4:29:30 PM4/12/13
to eureka_...@googlegroups.com
Unfortunately I have not received any attachments. Can you also include the configuration properties?
Reply all
Reply to author
Forward
0 new messages