Open bringwu opened 8 months ago
It works on 3.2.10.
@AlbumenJ my dubbo version is 3.2.10 too. there is my new test code:
api
public interface AsyncContext {
public CompletableFuture<Integer> newToken(String token);
CompletableFuture<Integer> sayHi(String name);
}
provider:
@DubboService
public class AsyncContextImpl implements AsyncContext {
private static final Logger logger = LoggerFactory.getLogger(AsyncContextImpl.class);
public CompletableFuture<Integer> newToken(String token) {
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
completableFuture = completableFuture.completeAsync(() -> {
logger.debug("tokenInfo:" + token);
return 1;
}, Executors.newFixedThreadPool(1));
RpcContextAttachment serverResponseContext = RpcContext.getServerResponseContext();
completableFuture = completableFuture.thenApply(ret -> {
serverResponseContext.setAttachment("tokenInfo", token);
return ret;
});
return completableFuture;
}
@Override
public CompletableFuture<Integer> sayHi(String name) {
String text = "hi, " + name;
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
completableFuture = completableFuture.completeAsync(() -> {
logger.debug(text);
return 1;
}, Executors.newFixedThreadPool(1));
RpcContextAttachment serverResponseContext = RpcContext.getServerResponseContext();
completableFuture = completableFuture.thenApply(ret -> {
serverResponseContext.setAttachment("testInfo", text);
return ret;
});
return completableFuture;
}
}
consumer:
@Component
public class AsyncContextTest {
private static final Logger logger = LoggerFactory.getLogger(AsyncContextTest.class);
@DubboReference
private AsyncContext asyncContext;
public void sayHi() {
CompletableFuture<Integer> future = asyncContext.sayHi("dubbo");
CompletableFuture<Void> completableFuture = future.thenAccept(ret->{
logger.debug("ret: " + ret + ", testInfo: " + RpcContext.getClientResponseContext().getAttachment("testInfo"));
});
try {
completableFuture.get();
} catch (Exception e) {
throw new RuntimeException("error", e);
}
}
public void newToken() {
String token = "dubboToken";
CompletableFuture<Integer> future = asyncContext.newToken(token);
CompletableFuture<Void> completableFuture = future.thenAccept(ret->{
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getClientResponseContext().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getServerAttachment().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getServiceContext().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getServerContext().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getCurrentServiceContext().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getServerResponseContext().getAttachment("tokenInfo"));
logger.debug("newToken: " + ret + ", rsp: " + RpcContext.getClientAttachment().getAttachment("tokenInfo"));
});
try {
completableFuture.get();
} catch (Exception e) {
throw new RuntimeException("error", e);
}
}
}
when Bootstrap class like that, it prints:
@SpringBootApplication
@EnableDubbo
public class Bootstrap {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Bootstrap.class, args);
applicationContext.getBean(AsyncContextTest.class).newToken();
applicationContext.getBean(AsyncContextTest.class).sayHi();
applicationContext.getBean(AsyncContextTest.class).sayHi();
applicationContext.stop();
}
}
2024-01-17 17:39:25.121 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: dubboToken
2024-01-17 17:39:25.121 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:39:25.122 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:39:25.122 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: dubboToken
2024-01-17 17:39:25.122 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:39:25.122 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:39:25.123 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:39:25.133 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo
2024-01-17 17:39:25.146 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo
when Bootstrap class like that, it prints error:
@SpringBootApplication
@EnableDubbo
public class Bootstrap {
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Bootstrap.class, args);
applicationContext.getBean(AsyncContextTest.class).sayHi();
applicationContext.getBean(AsyncContextTest.class).sayHi();
applicationContext.getBean(AsyncContextTest.class).newToken(); // see this
applicationContext.stop();
}
}
2024-01-17 17:45:11.242 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo
2024-01-17 17:45:11.249 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo
2024-01-17 17:45:11.258 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.258 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.259 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.260 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.260 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.260 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:45:11.260 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
it there any error in my code?
when I test multi times,it also prints
2024-01-17 17:57:05.029 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo
2024-01-17 17:57:05.038 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null
2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
and
2024-01-17 17:58:42.136 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null
2024-01-17 17:58:42.144 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null
2024-01-17 17:58:42.156 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.156 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
it seens that there is some bugs in RpcContext
3.3.0 beta-1 版本也不行 server:
AsyncContext asyncContext = RpcContext.startAsync();
return CompletableFuture.supplyAsync(() -> {
asyncContext.signalContextSwitch();
RpcContextAttachment serverContext = RpcContext.getServerContext();
// 往调用端传递参数
serverContext.setAttachment("server-key1", "server-");
client:
CompletableFuture<String> f = greetingService.helloFuture();
f.whenComplete((v, t) -> {
logger.info(RpcContext.getServerContext().getAttachment("server-key1"));
when I test multi times,it also prints
2024-01-17 17:57:05.029 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: hi, dubbo 2024-01-17 17:57:05.038 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null 2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.050 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:57:05.051 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
and
2024-01-17 17:58:42.136 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null 2024-01-17 17:58:42.144 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - ret: 1, testInfo: null 2024-01-17 17:58:42.156 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.156 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null 2024-01-17 17:58:42.157 [DubboClientHandler-thread-1] DEBUG c.b.d.s.c.service.AsyncContextTest - newToken: 1, rsp: null
it seens that there is some bugs in RpcContext
Can you please upgrade the demo to Github as a repo?
@AlbumenJ sorry, I have trouble pushing my repository to GitHub. i had tried many times, but still fail. you can create a maven project to test it.
there is the project maven config :
<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>3.1.5</version>
<relativePath />
</parent>
<groupId>com.bringwu.dubbo</groupId>
<artifactId>DubboTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>ProviderTest</module>
<module>ConsumerTest</module>
<module>ServiceApi</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<dubbo.version>3.2.10</dubbo.version>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bom</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
@AlbumenJ sorry, I have trouble pushing my repository to GitHub. i had tried many times, but still fail. you can create a maven project to test it.
there is the project maven config :
<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>3.1.5</version> <relativePath /> </parent> <groupId>com.bringwu.dubbo</groupId> <artifactId>DubboTest</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>ProviderTest</module> <module>ConsumerTest</module> <module>ServiceApi</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>17</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> <dubbo.version>3.2.10</dubbo.version> </properties> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
You can send the demo to my mail. (albumenj@apache.org)
@AlbumenJ sorry, I have trouble pushing my repository to GitHub. i had tried many times, but still fail. you can create a maven project to test it. there is the project maven config :
<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>3.1.5</version> <relativePath /> </parent> <groupId>com.bringwu.dubbo</groupId> <artifactId>DubboTest</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>ProviderTest</module> <module>ConsumerTest</module> <module>ServiceApi</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>17</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> <dubbo.version>3.2.10</dubbo.version> </properties> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
You can send the demo to my mail. (albumenj@apache.org)
the email has been sent to your email address
@AlbumenJ sorry, I have trouble pushing my repository to GitHub. i had tried many times, but still fail. you can create a maven project to test it. there is the project maven config :
<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>3.1.5</version> <relativePath /> </parent> <groupId>com.bringwu.dubbo</groupId> <artifactId>DubboTest</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>ProviderTest</module> <module>ConsumerTest</module> <module>ServiceApi</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>17</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> <dubbo.version>3.2.10</dubbo.version> </properties> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
You can send the demo to my mail. (albumenj@apache.org)
the email has been sent to your email address
Get it. I will test it later.
@bringwu In your demo, Dubbo process the result before set attachment.
Add sleep before return to make sure that serverResponseContext.setAttachment("tokenInfo", token)
has been processed.
Then it work.
@bringwu In your demo, Dubbo process the result before set attachment.
Add sleep before return to make sure that
serverResponseContext.setAttachment("tokenInfo", token)
has been processed.Then it work.
Adding sleep can make an asynchronous program behave synchronously, but it can lead to performance issues. I think Dubbo should optimize this problem to allow programs to execute purely asynchronously.
@bringwu In your demo, Dubbo process the result before set attachment. Add sleep before return to make sure that
serverResponseContext.setAttachment("tokenInfo", token)
has been processed. Then it work.Adding sleep can make an asynchronous program behave synchronously, but it can lead to performance issues. I think Dubbo should optimize this problem to allow programs to execute purely asynchronously.
If you want to use local invoke by default, it would be better to use spring bean directly instead of using Dubbo bean. That performance would be better.
This is a terrible solution. I can't believe it was proposed by official personnel. I'll figure out a solution on my own.
to mark for me
provider service method:
consumer :
provider的方法是异步执行,异步执行完后才能往RpcContext设置回应附加信息,这种情况回应附加信息没法传递到consumer这边