Commit 7c8cf7ed by Nepxion

测试用例增加Feign接口

parent d80f611e
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
<!-- <artifactId>discovery-plugin-starter-zookeeper</artifactId> --> <!-- <artifactId>discovery-plugin-starter-zookeeper</artifactId> -->
<version>${discovery.plugin.version}</version> <version>${discovery.plugin.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -12,15 +12,17 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,15 +12,17 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
import com.nepxion.discovery.plugin.example.extension.MyDiscoveryListener; import com.nepxion.discovery.plugin.example.extension.MyDiscoveryListener;
import com.nepxion.discovery.plugin.example.extension.MyRegisterListener; import com.nepxion.discovery.plugin.example.extension.MyRegisterListener;
import com.nepxion.discovery.plugin.example.extension.MySubscriber; import com.nepxion.discovery.plugin.example.extension.MySubscriber;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationA1 { public class DiscoveryApplicationA1 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "a1"); System.setProperty("spring.profiles.active", "a1");
......
...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter; import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationB1 { public class DiscoveryApplicationB1 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "b1"); System.setProperty("spring.profiles.active", "b1");
......
...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter; import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationB2 { public class DiscoveryApplicationB2 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "b2"); System.setProperty("spring.profiles.active", "b2");
......
...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter; import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationC1 { public class DiscoveryApplicationC1 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "c1"); System.setProperty("spring.profiles.active", "c1");
......
...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter; import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationC2 { public class DiscoveryApplicationC2 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "c2"); System.setProperty("spring.profiles.active", "c2");
......
...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example; ...@@ -12,12 +12,14 @@ package com.nepxion.discovery.plugin.example;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import com.nepxion.discovery.plugin.example.impl.DiscoveryConfigAdapter; import com.nepxion.discovery.plugin.example.adapter.DiscoveryConfigAdapter;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients
public class DiscoveryApplicationC3 { public class DiscoveryApplicationC3 {
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("spring.profiles.active", "c3"); System.setProperty("spring.profiles.active", "c3");
......
package com.nepxion.discovery.plugin.example.impl; package com.nepxion.discovery.plugin.example.adapter;
/** /**
* <p>Title: Nepxion Discovery</p> * <p>Title: Nepxion Discovery</p>
......
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(value = "discovery-springcloud-example-a")
public interface AFeign {
@RequestMapping(path = "/invoke", method = RequestMethod.POST)
String invoke(@RequestBody String value);
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-a")
public class AFeignImpl extends AbstractFeignImpl implements AFeign {
@Autowired
private BFeign bFeign;
@Override
public String invoke(@RequestBody String value) {
value = doInvoke(value);
value = bFeign.invoke(value);
System.out.println("调用路径:" + value);
return value;
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
public class AbstractFeignImpl {
@Autowired
protected ConfigurableEnvironment environment;
@Autowired
private PluginAdapter pluginAdapter;
public String doInvoke(String value) {
String serviceId = environment.getProperty(PluginConstant.SPRING_APPLICATION_NAME);
String version = pluginAdapter.getVersion();
return value + " -> " + serviceId + "[" + version + "]";
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(value = "discovery-springcloud-example-b")
public interface BFeign {
@RequestMapping(path = "/invoke", method = RequestMethod.POST)
String invoke(@RequestBody String value);
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-b")
public class BFeignImpl extends AbstractFeignImpl implements BFeign {
@Autowired
private CFeign cFeign;
@Override
public String invoke(@RequestBody String value) {
value = doInvoke(value);
value = cFeign.invoke(value);
System.out.println("调用路径:" + value);
return value;
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(value = "discovery-springcloud-example-c")
public interface CFeign {
@RequestMapping(path = "/invoke", method = RequestMethod.POST)
String invoke(@RequestBody String value);
}
\ No newline at end of file
package com.nepxion.discovery.plugin.example.feign;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
@RestController
@ConditionalOnProperty(name = PluginConstant.SPRING_APPLICATION_NAME, havingValue = "discovery-springcloud-example-c")
public class CFeignImpl extends AbstractFeignImpl implements CFeign {
@Override
public String invoke(@RequestBody String value) {
value = doInvoke(value);
System.out.println("调用路径:" + value);
return value;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment