SpringBoot2.2.1+Dubbo2.7.4.1+Dub

2019-12-08  本文已影响0人  VP牧码人

1. 依赖工具

  1. SpringBoot2.2.1
  2. Dubbo2.7.4.1
  3. DubboAdmin(20191208最新版)

2. Springboot-Dubbo-Server

15758161944391.jpg
  1. 主要的依赖
  <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.codingvip</groupId>
    <artifactId>sdu-dubbo-client-boot</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>sdu-dubbo-client-boot</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.codingvip</groupId>
            <artifactId>stu-dubbo-client</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-registry-zookeeper</artifactId>
            <version>2.7.4.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

@Service
@Component
public class UserServiceImpl implements UserService {
    @Override
    public String getName(int id) {
        return null;
    }
    @Override
    public User getUserById(int id) {
        User user = new User();
        user.setUserName("coding:Demo:" 
        user.setId(id);
        return user;
    }
    @Override
    public User getUser(UserParam param) {
        return null;
    }
    }
    
@EnableDubbo
@SpringBootApplication
public class SduDubboServerBootApplication {


 
   public static void main(String[] args) {
        SpringApplication.run(SduDubboServerBootApplication.class, args);
    }


}
dubbo.application.name=simple
dubbo.registry.address=zookeeper://localhost:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1

2019-12-08 22:31:53.878  INFO 73677 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
2019-12-08 22:31:53.878  INFO 73677 --- [           main] o.a.c.f.imps.CuratorFrameworkImpl        : Default schema
2019-12-08 22:31:53.907  INFO 73677 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2019-12-08 22:31:53.922  INFO 73677 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x1000156f6df0014, negotiated timeout = 40000
2019-12-08 22:31:53.930  INFO 73677 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager     : State change: CONNECTED
2019-12-08 22:31:54.483  INFO 73677 --- [           main] c.c.s.SduDubboServerBootApplication      : Started SduDubboServerBootApplication in 3.565 seconds (JVM running for 4.918)
2019-12-08 22:31:54.487  INFO 73677 --- [pool-1-thread-1] .b.c.e.AwaitingNonWebApplicationListener :   [Dubbo] Current Spring Boot Application is await...

3. Springboot-Dubbo-Client

@EnableDubbo
@SpringBootApplication
public class SduDubboClientBootApplication {
    @Reference
    UserService userService;
    public static void main(String[] args) {  SpringApplication.run(SduDubboClientBootApplication.class, args).close();
        System.out.println("调用完成");
    }
    @Bean
    public ApplicationRunner getBean() {
        return args -> {
        System.out.println(userService.getUserById(123));
        };
    }

}
dubbo.application.name=youngMan
dubbo.registry.address=zookeeper://localhost:2181
dubbo.reference.timeout=5000
User{id=11, userName='coding:Demo:', age=0, sex='null'}
2019-12-08 22:34:55.429  INFO 74177 --- [pool-1-thread-1] .b.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is await...
2019-12-08 22:34:55.430  INFO 74177 --- [           main] .b.c.e.AwaitingNonWebApplicationListener :  [Dubbo] Current Spring Boot Application is about to shutdown...
2019-12-08 22:34:55.438  INFO 74177 --- [tor-Framework-0] o.a.c.f.imps.CuratorFrameworkImpl        : backgroundOperationsLoop exiting
2019-12-08 22:34:55.444  INFO 74177 --- [ain-EventThread] org.apache.zookeeper.ClientCnxn          : EventThread shut down for session: 0x1000156f6df0016
2019-12-08 22:34:55.444  INFO 74177 --- [           main] org.apache.zookeeper.ZooKeeper           : Session: 0x1000156f6df0016 closed
2019-12-08 22:34:55.452  INFO 74177 --- [           main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy0@6ada9c0c was destroying!
2019-12-08 22:34:55.452  INFO 74177 --- [           main] f.a.ReferenceAnnotationBeanPostProcessor : class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!
调用完成
断开与目标 VM 的连接,地址:'127.0.0.1:62058', transport: 'socket'

4. Dubbo-admin

git clone https://github.com/apache/dubbo-admin
2019-12-08 21:55:06.917  INFO 65028 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
2019-12-08 22:16:21.561  INFO 65028 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-12-08 22:16:21.581  INFO 65028 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 20 ms
proxyTable: {
      '/': {
        target: 'http://localhost:8888/',
        changeOrigin: true,
        pathRewrite: {
          '^/': '/'
        }
      }
    },
npm install  --registry=https://registry.npm.taobao.org

待执行完成后运行:

 npm run dev  

结果如下:

DONE  Compiled successfully in 18504ms 10:15:55 PM
Your application is running here: http://localhost:8081  
15758182213643.jpg
上一篇下一篇

猜你喜欢

热点阅读