feign 改为 dubbo

This commit is contained in:
GYJ
2025-02-11 14:27:51 +08:00
parent 30b9cef27f
commit 009cd44653
19 changed files with 194 additions and 106 deletions

View File

@@ -1,10 +1,10 @@
package com.czg;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
@@ -12,9 +12,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableTransactionManagement
@MapperScan("com.czg.service.account.mapper")
@EnableDubbo
public class AccountApplication {
public static void main(String[] args) {
SpringApplication.run(AccountApplication.class, args);

View File

@@ -1,9 +1,9 @@
package com.czg.controller;
import com.czg.service.account.feign.FeignSystemService;
import com.czg.service.RedisService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.fastjson2.JSONObject;
import com.czg.system.dto.SysParamsDTO;
import com.czg.system.service.SysParamsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -14,18 +14,13 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/feign")
public class FeignController {
@Resource
private FeignSystemService feignSystemService;
@Autowired
private RedisService redisService;
@DubboReference
private SysParamsService sysParamsService;
@RequestMapping("/test")
public String test() {
String string = feignSystemService.testCall("sssss");
System.out.println(string);
redisService.set("sssss", string);
return "test";
SysParamsDTO test = sysParamsService.getParamsByCode2("test");
return JSONObject.toJSONString(test);
}
}

View File

@@ -15,18 +15,19 @@ spring:
cloud:
nacos:
config:
bootstrap:
enabled: true
data-id: system-server
group: DEFAULT_GROUP
auto-refresh: true
server-addr: 101.37.12.135:8848
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
file-extension: yaml
discovery:
server-addr: 101.37.12.135:8848
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
dubbo:
application:
name: account-server
qos-port: 22221
qos-enable: true
registry:
address: nacos://101.37.12.135:8848 # Nacos 服务地址
group: server
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
protocol:
port: 9101

View File

@@ -47,6 +47,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>

View File

@@ -1,16 +1,20 @@
package com.czg;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author ww
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan("com.czg.service.system.mapper")
@EnableDubbo
public class SystemApplication {
public static void main(String[] args) {

View File

@@ -1,6 +1,11 @@
package com.czg.controller;
import com.czg.sa.StpKit;
import com.czg.SysParamsDTO2;
import com.czg.resp.CzgResult;
import com.czg.system.dto.SysParamsDTO;
import com.czg.system.service.SysParamsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -12,8 +17,18 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/admin/feign")
public class FeignController {
@Resource
private SysParamsService sysParamsService;
@RequestMapping("/testCall/{name}")
public String testCall(@PathVariable String name) {
return "system-server:" + name;
public CzgResult<SysParamsDTO2> testCall(@PathVariable String name) {
return CzgResult.success(new SysParamsDTO2().setParamCode("system-server:" + name));
}
@GetMapping("/sysParam/code/{code}")
public SysParamsDTO getParamsByCode(@PathVariable String code) {
CzgResult<SysParamsDTO> paramsByCode = sysParamsService.getParamsByCode(code);
return paramsByCode.getData();
}
}

View File

@@ -1,8 +1,8 @@
package com.czg.controller;
import com.czg.resp.CzgResult;
import com.czg.service.system.dto.SysParamsDTO;
import com.czg.service.system.service.SysParamsService;
import com.czg.system.dto.SysParamsDTO;
import com.czg.system.service.SysParamsService;
import com.czg.validator.group.InsertGroup;
import com.czg.validator.group.UpdateGroup;
import jakarta.annotation.Resource;

View File

@@ -24,3 +24,15 @@ spring:
discovery:
server-addr: 101.37.12.135:8848
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
dubbo:
application:
name: system-server
qos-port: 22224
qos-enable: true
registry:
address: nacos://101.37.12.135:8848 # Nacos 服务地址
group: server
namespace: 237e1905-0a66-4375-9bb6-a51c3c034aca
protocol:
port: 9401