Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,58 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<parent>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-spring-boot-discovery</artifactId>
<version>0.1.0-m2-SNAPSHOT</version>
</parent>
<artifactId>demo-spring-boot-discovery-client</artifactId>

<properties>
<demo.main>io.servicecomb.demo.discovery.client.DiscoveryClient</demo.main>
</properties>
<dependencies>
<dependency>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.odavid.maven.plugins</groupId>
<artifactId>mixin-maven-plugin</artifactId>
<configuration>
<mixins>
<mixin>
<groupId>io.servicecomb.demo</groupId>
<artifactId>docker-run-config</artifactId>
<version>0.1.0-m2-SNAPSHOT</version>
</mixin>
</mixins>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>docker</id>
<properties>
<demo.service.name>demo-spring-boot-discovery-server</demo.service.name>
<demo.vm.options>-Dcse.rest.address=0.0.0.0:8069</demo.vm.options>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,24 @@

package io.servicecomb.demo.discovery.client;

import java.util.List;

import java.net.URI;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
* Sukesh
*/
@RestController
@RequestMapping(path = "/controller", produces = MediaType.APPLICATION_JSON)
public class Controller {

@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private DiscoveryClient discoveryClient;

@RequestMapping(path = "/instances", method = RequestMethod.GET)
public void getInstances() {
List<ServiceInstance> instances = discoveryClient.getInstances("springmvc");
for (ServiceInstance si : instances) {
System.out.println(si.getUri().toString());
}

}
@RequestMapping(path = "/instances", method = RequestMethod.GET)
public URI getInstances() {
return discoveryClient.getInstances("discovery").get(0).getUri();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,42 @@

package io.servicecomb.demo.discovery.client;

import java.net.URI;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.client.RestTemplate;

import com.netflix.config.DynamicPropertyFactory;

import io.servicecomb.demo.TestMgr;
import io.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import io.servicecomb.springboot.starter.provider.EnableServiceComb;

/**
* Sukesh
*/
@SpringBootApplication
@EnableServiceComb
@EnableDiscoveryClient
public class DiscoveryClient {

public static void main(String[] args) throws Exception {
SpringApplication.run(DiscoveryClient.class, args);
}
private static RestTemplate restTemplate;

public static void main(String[] args) throws Exception {
SpringApplication.run(DiscoveryClient.class, args);
runIT();
}

private static void runIT() throws Exception {
restTemplate = RestTemplateBuilder.create();
new DiscoveryClient().testInstances(restTemplate);
TestMgr.summary();
}

private void testInstances(RestTemplate template) {
String port = DynamicPropertyFactory.getInstance().getStringProperty("server.port", "9993").get();
String urlPrefix = "http://localhost:" + port + "/controller/instances";
URI result = template.getForObject(urlPrefix, URI.class);
TestMgr.check(8069, result.getPort());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server:
port: 8088
port: 9993
spring:
cloud:
cse:
host: 127.0.0.1
port: 9980
port: 30100
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
APPLICATION_ID: springmvctest
APPLICATION_ID: discoverytest
service_description:
name: springmvc
version: 0.0.1
name: discovery
version: 0.0.2
cse:
service:
registry:
address: http://127.0.0.1:9980
address: http://127.0.0.1:30100
references:
springmvc:
version-rule: 0.0.1
discovery:
version-rule: 0.0.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.servicecomb.demo.discovery.client;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import org.junit.Before;
import org.junit.Test;

import io.servicecomb.demo.TestMgr;

public class DiscoveryClientIT {

@Before
public void setUp() {
TestMgr.errors().clear();
}

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test doesn't have much meaning except ensured DiscoveryClient can be started up.

Nothing related to how services discovery with spring cloud integration and load balancing was tested.

We have to be sure we are able to forward requests to corresponding services from zuul with service center

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written demo/IT code for:

  1. To test the discovery of particular micro-service
  2. To test the Zuul Proxy gateway feature to redirect the request to proper micro-service.

public void clientGetsNoError() throws Exception {
DiscoveryClient.main(new String[0]);
System.out.println(TestMgr.errors().toString());
assertThat(TestMgr.errors().isEmpty(), is(true));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-spring-boot-discovery</artifactId>
<version>0.1.0-m2-SNAPSHOT</version>
</parent>
<artifactId>demo-spring-boot-discovery-server</artifactId>
<name>demo-spring-boot-discovery-server</name>
<dependencies>
<dependency>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-schema</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>provider-springmvc</artifactId>
</dependency>
</dependencies>

<properties>
<demo.main>io.servicecomb.demo.discovery.server.DiscoveryServer</demo.main>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.github.odavid.maven.plugins</groupId>
<artifactId>mixin-maven-plugin</artifactId>
<configuration>
<mixins>
<mixin>
<groupId>io.servicecomb.demo</groupId>
<artifactId>docker-build-config</artifactId>
<version>0.1.0-m2-SNAPSHOT</version>
</mixin>
</mixins>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>docker</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading