Skip to content

Commit

Permalink
测试本地调用不走remote
Browse files Browse the repository at this point in the history
  • Loading branch information
qinfuxiang committed Nov 4, 2021
1 parent 603b53e commit 35ba2f6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ spring:
file-extension: yaml
# 共享的配置列表
shared-dataids: service-common.yaml
refreshable-dataids: service-common.yaml
grpc:
remote-servers:
- server: user
host: 127.0.0.1
port: 6565
refreshable-dataids: service-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
<groupId>fast.cloud.nacos</groupId>
<artifactId>grpc-starter-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</exclusion>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@SpringBootApplication(scanBasePackages = {"fast.cloud.nacos"})
//@GrpcServiceScan(packages = {"fast.cloud.nacos.grpc.api"})
public class GrpcStarterProviderApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@

import fast.cloud.nacos.grpc.api.entity.UserEntity;
import fast.cloud.nacos.grpc.api.service.UserServiceBySofaHessian;
import java.util.List;
import fast.cloud.nacos.grpc.starter.annotation.GrpcService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/v0/user")
public class V0UserController {

private final UserServiceBySofaHessian userServiceBySofaHessian;
@GrpcService
private UserServiceBySofaHessian userServiceBySofaHessian;

@PostMapping("/add")
public UserEntity insertUser(@RequestBody UserEntity userEntity){
public UserEntity insertUser(@RequestBody UserEntity userEntity) {
userServiceBySofaHessian.insert(userEntity);
return userEntity;
}

@GetMapping("/list")
public List<UserEntity> findAllUser(){
public List<UserEntity> findAllUser() {
return userServiceBySofaHessian.findAll();
}

@PostMapping("/remove")
public String removeUser(@RequestParam("id") Long id){
public String removeUser(@RequestParam("id") Long id) {
userServiceBySofaHessian.deleteById(id);
return "success";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fast.cloud.nacos.provider.controller;

import fast.cloud.nacos.grpc.api.entity.UserEntity;
import fast.cloud.nacos.grpc.api.service.UserServiceByProtoStuff;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/v2/user")
public class V2UserController {

@Resource
private UserServiceByProtoStuff userServiceByProtoStuff;

@PostMapping("/add")
public UserEntity insertUser(@RequestBody UserEntity userEntity){
userServiceByProtoStuff.insert(userEntity);
return userEntity;
}

@GetMapping("/list")
public List<UserEntity> findAllUser(){
return userServiceByProtoStuff.findAll();
}

@PostMapping("/remove")
public String removeUser(@RequestParam("id") Long id){
userServiceByProtoStuff.deleteById(id);
return "success";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import fast.cloud.nacos.grpc.api.entity.UserEntity;
import fast.cloud.nacos.grpc.api.service.UserServiceByProtoStuff;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
* service 只是交给spring代理,如果没有本地调用,可以去掉
*/
@Service
@Slf4j
public class UserServiceByProtoStuffImpl implements UserServiceByProtoStuff {
Expand Down

0 comments on commit 35ba2f6

Please sign in to comment.