mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-09-19 10:08:07 +08:00
新增 Dubbo 集成插件
This commit is contained in:
13
sa-token-demo/sa-token-demo-dubbo-consumer/.gitignore
vendored
Normal file
13
sa-token-demo/sa-token-demo-dubbo-consumer/.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
target/
|
||||
.project
|
||||
.classpath
|
||||
.settings
|
||||
|
||||
/.idea/
|
||||
|
||||
node_modules/
|
||||
bin/
|
||||
.settings/
|
||||
unpackage/
|
||||
/.apt_generated/
|
||||
/.apt_generated_tests/
|
75
sa-token-demo/sa-token-demo-dubbo-consumer/pom.xml
Normal file
75
sa-token-demo/sa-token-demo-dubbo-consumer/pom.xml
Normal file
@@ -0,0 +1,75 @@
|
||||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.pj</groupId>
|
||||
<artifactId>sa-token-demo-dubbo-consumer</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<!-- SpringBoot -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.3.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<!-- 指定一些属性 -->
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- SpringBoot Web模块 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<version>1.27.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token整合 Redis (使用jackson序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-dao-redis-jackson</artifactId>
|
||||
<version>1.27.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>2.7.11</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo 注册到 Nacos -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-nacos</artifactId>
|
||||
<version>2.7.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Sa-Token 整合 Dubbo -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-context-dubbo</artifactId>
|
||||
<version>1.27.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@@ -0,0 +1,22 @@
|
||||
package com.pj;
|
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Dubbo 服务消费端
|
||||
*
|
||||
* @author kong
|
||||
*
|
||||
*/
|
||||
@EnableDubbo
|
||||
@SpringBootApplication
|
||||
public class ConsumerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConsumerApplication.class, args);
|
||||
System.out.println("ConsumerApplication 启动成功");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.pj.more;
|
||||
|
||||
public interface DemoService {
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param loginId 账号id
|
||||
*/
|
||||
void doLogin(Object loginId);
|
||||
|
||||
/**
|
||||
* 判断是否登录,打印状态
|
||||
*/
|
||||
void isLogin(String str);
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package com.pj.more;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
@RestController
|
||||
public class TestController {
|
||||
|
||||
@DubboReference
|
||||
private DemoService demoService;
|
||||
|
||||
// Consumer端登录,状态传播到Provider端
|
||||
@RequestMapping("test")
|
||||
public String test() {
|
||||
demoService.isLogin("----------- 登录前 ");
|
||||
|
||||
StpUtil.login(10001);
|
||||
|
||||
demoService.isLogin("----------- 登录后 ");
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
// Provider端登录,状态回传到Consumer端
|
||||
@RequestMapping("test2")
|
||||
public String test2() {
|
||||
System.out.println("----------- 登录前 ");
|
||||
System.out.println("Token值:" + StpUtil.getTokenValue());
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
|
||||
demoService.doLogin(10002);
|
||||
|
||||
System.out.println("----------- 登录后 ");
|
||||
System.out.println("Token值:" + StpUtil.getTokenValue());
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
// Consumer端登录,状态在Consumer端保持
|
||||
@RequestMapping("test3")
|
||||
public String test3() {
|
||||
System.out.println("----------- 登录前 ");
|
||||
System.out.println("Token值:" + StpUtil.getTokenValue());
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
|
||||
StpUtil.login(10003);
|
||||
demoService.isLogin("----------- Provider状态");
|
||||
|
||||
System.out.println("----------- 登录后 ");
|
||||
System.out.println("Token值:" + StpUtil.getTokenValue());
|
||||
System.out.println("是否登录:" + StpUtil.isLogin());
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
server:
|
||||
# 端口号
|
||||
port: 8081
|
||||
|
||||
spring:
|
||||
# redis配置
|
||||
redis:
|
||||
# Redis数据库索引(默认为0)
|
||||
database: 0
|
||||
# Redis服务器地址
|
||||
host: 127.0.0.1
|
||||
# Redis服务器连接端口
|
||||
port: 6379
|
||||
# Redis服务器连接密码(默认为空)
|
||||
password:
|
||||
# 连接超时时间
|
||||
|
||||
dubbo:
|
||||
application:
|
||||
# 服务名称
|
||||
name: dubbo-consumer-demo
|
||||
registry:
|
||||
# 注册中心地址
|
||||
address: nacos://127.0.0.1:8001
|
Reference in New Issue
Block a user