Bläddra i källkod

远程调用服务测试例子

qzyReal 2 år sedan
förälder
incheckning
023366e49c

+ 23 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterface.java

@@ -0,0 +1,23 @@
+package com.pj.api.client.admin;
+
+import com.pj.api.FeignInterceptor;
+import com.pj.api.consts.FeignConsts;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * 系统配置 服务
+ * @author kong
+ *
+ */
+@FeignClient(
+		name = FeignConsts.SP_ADMIN, 				// 服务名称
+		configuration = FeignInterceptor.class,		// 请求拦截器 
+		fallbackFactory = AdminInterfaceFallback.class	// 服务降级
+		)	
+public interface AdminInterface {
+
+
+	
+}

+ 35 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterfaceFallback.java

@@ -0,0 +1,35 @@
+package com.pj.api.client.admin;
+
+import feign.hystrix.FallbackFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * 系统配置 服务降级处理
+ * @author kong
+ *
+ */
+@Component
+public class AdminInterfaceFallback implements FallbackFactory<AdminInterface>
+{
+
+	private static final Logger log = LoggerFactory.getLogger(AdminInterfaceFallback.class);
+	
+	/**
+	 * 服务降级时触发的方法 
+	 */
+	@Override
+	public AdminInterface create(Throwable cause) {
+		
+		
+		log.error("--------------------系统配置服务异常,触发降级: {}", cause.getMessage());
+		
+		// 返回熔断后的对象 
+		return new AdminInterface() {
+
+			
+		};
+	}
+
+}

+ 2 - 1
sp-core/sp-api/src/main/java/com/pj/api/consts/FeignConsts.java

@@ -7,7 +7,8 @@ public class FeignConsts {
 	 * 服务名:sp-home 
 	 */
 	public static final String SP_HOME = "sp-home";
-	
+	public static final String SP_ADMIN = "sp-admin";
+
 	
 	
 	

+ 12 - 7
sp-service/sp-admin/src/main/java/com/pj/project4sp/admin/SpAdminController.java

@@ -150,13 +150,18 @@ public class SpAdminController {
 		int line = spAdminMapper.update(obj);
 		return AjaxJson.getByLine(line);
 	}
-	
-	
-	
-	
-	
-	
-	
+
+
+
+
+
+
+	/** 查 - 集合 */
+	@RequestMapping("rpc/getList")
+	List<SpAdmin> rpcGetList(){
+		SoMap so = SoMap.getRequestSoMap();
+		return spAdminMapper.getList(so.startPage());
+	}