dubbo2.6.3添加了provider=>consumer的attachment,同步跟进
diff --git a/examples/hello-koa/dubbo/dubbo.js b/examples/hello-koa/dubbo/dubbo.js
index 558926e..a57aec9 100644
--- a/examples/hello-koa/dubbo/dubbo.js
+++ b/examples/hello-koa/dubbo/dubbo.js
@@ -20,6 +20,11 @@
dubboSetting,
}));
+dubbo.use(async (ctx, next) => {
+ await next();
+ console.log('-providerAttachments-->', ctx.providerAttachments);
+});
+
// dubbo.ready().then(() => {
// console.log('dubbo was ready');
// });
diff --git a/java/dubbo-demo/dubbo-demo-api/pom.xml b/java/dubbo-demo/dubbo-demo-api/pom.xml
index af2220c..39639a9 100644
--- a/java/dubbo-demo/dubbo-demo-api/pom.xml
+++ b/java/dubbo-demo/dubbo-demo-api/pom.xml
@@ -34,7 +34,7 @@
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-demo</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
</parent>
<artifactId>dubbo-demo-api</artifactId>
<packaging>jar</packaging>
diff --git a/java/dubbo-demo/dubbo-demo-consumer/pom.xml b/java/dubbo-demo/dubbo-demo-consumer/pom.xml
index 47d77ff..0eb0797 100644
--- a/java/dubbo-demo/dubbo-demo-consumer/pom.xml
+++ b/java/dubbo-demo/dubbo-demo-consumer/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-demo</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
</parent>
<artifactId>dubbo-demo-consumer</artifactId>
<packaging>jar</packaging>
diff --git a/java/dubbo-demo/dubbo-demo-provider/pom.xml b/java/dubbo-demo/dubbo-demo-provider/pom.xml
index f437da6..fdc2a86 100644
--- a/java/dubbo-demo/dubbo-demo-provider/pom.xml
+++ b/java/dubbo-demo/dubbo-demo-provider/pom.xml
@@ -1,12 +1,12 @@
<!--
- Copyright 1999-2011 Alibaba Group.
- -
+ -
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- -
+ -
- http://www.apache.org/licenses/LICENSE-2.0
- -
+ -
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,7 +19,7 @@
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-demo</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
</parent>
<artifactId>dubbo-demo-provider</artifactId>
<packaging>jar</packaging>
@@ -125,4 +125,4 @@
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/java/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml b/java/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
index 702026c..59c1a8f 100644
--- a/java/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
+++ b/java/dubbo-demo/dubbo-demo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
- -
+ -
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- -
+ -
- http://www.apache.org/licenses/LICENSE-2.0
- -
+ -
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,7 @@
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="demo-provider"/>
- <dubbo:registry protocol="zookeeper" address="localhost:2181"/>
+ <dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"/>
<dubbo:provider timeout="1500"/>
@@ -44,4 +44,4 @@
<dubbo:service interface="com.alibaba.dubbo.demo.BasicTypeProvider" ref="basicTypeProvider" version="2.0.0"/>
<dubbo:service interface="com.alibaba.dubbo.demo.ErrorProvider" ref="errorProvider" version="1.0.0"/>
-</beans>
\ No newline at end of file
+</beans>
diff --git a/java/dubbo-demo/pom.xml b/java/dubbo-demo/pom.xml
index dd8f575..8223eca 100644
--- a/java/dubbo-demo/pom.xml
+++ b/java/dubbo-demo/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
</parent>
<artifactId>dubbo-demo</artifactId>
<packaging>pom</packaging>
diff --git a/java/pom.xml b/java/pom.xml
index f604d2a..f0447f3 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -1,12 +1,12 @@
<!--
- Copyright 1999-2011 Alibaba Group.
- -
+ -
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- -
+ -
- http://www.apache.org/licenses/LICENSE-2.0
- -
+ -
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
- <version>2.5.7</version>
+ <version>2.6.3</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<description>The parent project of dubbo</description>
@@ -581,4 +581,4 @@
<timezone>+8</timezone>
</developer>
</developers>
-</project>
+</project>
diff --git a/packages/dubbo/src/context.ts b/packages/dubbo/src/context.ts
index 6de61e7..f298e62 100644
--- a/packages/dubbo/src/context.ts
+++ b/packages/dubbo/src/context.ts
@@ -33,6 +33,7 @@
this._body = {err: null, res: null};
this._application = {name: 'dubbo2.js'};
this._attachments = {};
+ this._providerAttachments = {};
this._request = <IContextRequestParam>{
requestId: id(),
};
@@ -98,6 +99,12 @@
*/
private _attachments: Object;
+ /**
+ * dubbo2.6.3 增加了 provider => consumer的attachments的能力
+ * https://github.com/apache/incubator-dubbo/issues/889
+ */
+ private _providerAttachments: Object;
+
static create<T = any>() {
return new Context<T>();
}
@@ -316,6 +323,23 @@
return this._attachments;
}
+ /**
+ * 设置provider传递过来的attachments
+ * @since dubbo2.6.3
+ */
+ set providerAttachments(param: Object) {
+ log('set provider attachments->%o', param);
+ this._providerAttachments = param;
+ }
+
+ /**
+ * 设置provider传递过来的attachments
+ * @since dubbo2.6.3
+ */
+ get providerAttachments() {
+ return this._providerAttachments;
+ }
+
//===============private method==========================
private static _checkHessianParam(param: any): param is IHessianType {
return (
diff --git a/packages/dubbo/src/decode.ts b/packages/dubbo/src/decode.ts
index 4de4265..671b167 100644
--- a/packages/dubbo/src/decode.ts
+++ b/packages/dubbo/src/decode.ts
@@ -43,12 +43,17 @@
RESPONSE_WITH_EXCEPTION = 0,
RESPONSE_VALUE = 1,
RESPONSE_NULL_VALUE = 2,
+ //@since dubbo2.6.3
+ RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS = 3,
+ RESPONSE_VALUE_WITH_ATTACHMENTS = 4,
+ RESPONSE_NULL_VALUE_WITH_ATTACHMENTS = 5,
}
//com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encodeResponse/decode
export function decode<T>(bytes: Buffer): IDubboResponse<T> {
let res = null;
let err = null;
+ let attachments = {};
// set request and serialization flag.
//字节位置[4-11] 8 bytes
@@ -71,6 +76,7 @@
return {
err: new DubboDecodeError(bytes.slice(HEADER_LENGTH).toString()),
res: null,
+ attachments,
requestId,
};
}
@@ -89,10 +95,12 @@
case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_VALUE:
err = null;
res = body.read();
+ attachments = {};
break;
case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_NULL_VALUE:
err = null;
res = null;
+ attachments = {};
break;
case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_WITH_EXCEPTION:
const exception = body.read();
@@ -101,10 +109,27 @@
? exception
: new DubboDecodeError(exception);
res = null;
+ attachments = {};
+ break;
+ case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_NULL_VALUE_WITH_ATTACHMENTS:
+ err = null;
+ res = null;
+ attachments = body.read();
+ break;
+ case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_VALUE_WITH_ATTACHMENTS:
+ err = null;
+ res = body.read();
+ attachments = body.read();
+ break;
+ case DUBBO_RESPONSE_BODY_FLAG.RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS:
+ const exp = body.read();
+ err = exp instanceof Error ? exp : new DubboDecodeError(exp);
+ res = null;
+ attachments = body.read();
break;
default:
err = new DubboDecodeError(
- `Unknown result flag, expect '0' '1' '2', get ${flag})`,
+ `Unknown result flag, expect '0/1/2/3/4/5', get ${flag})`,
);
res = null;
}
@@ -113,5 +138,6 @@
requestId,
err,
res,
+ attachments,
};
}
diff --git a/packages/dubbo/src/queue.ts b/packages/dubbo/src/queue.ts
index e6fc390..08f63b2 100644
--- a/packages/dubbo/src/queue.ts
+++ b/packages/dubbo/src/queue.ts
@@ -131,7 +131,7 @@
this._requestQueue.clear();
}
- failed(requestId: TRequestId, err: Error) {
+ failed(requestId: TRequestId, err: Error, attachments: Object = {}) {
const ctx = this._requestQueue.get(requestId);
if (!ctx) {
return;
@@ -149,6 +149,8 @@
if (err['cause']) {
delete err['cause']['cause'];
}
+ //dubbo2.6.3
+ ctx.providerAttachments = attachments;
ctx.cleanTimeout();
ctx.reject(err);
this._clear(requestId);
@@ -178,12 +180,14 @@
}
}
- resolve(requestId, res) {
+ resolve(requestId: TRequestId, res: any, attachments: Object = {}) {
const ctx = this._requestQueue.get(requestId);
if (!ctx) {
return;
}
log('resolve requestId#%d, res: %O', requestId, res);
+ //dubbo2.6.3
+ ctx.providerAttachments = attachments;
ctx.cleanTimeout();
ctx.resolve(res);
this._clear(requestId);
diff --git a/packages/dubbo/src/scheduler.ts b/packages/dubbo/src/scheduler.ts
index 9c35c7c..941978d 100644
--- a/packages/dubbo/src/scheduler.ts
+++ b/packages/dubbo/src/scheduler.ts
@@ -19,7 +19,7 @@
import DubboAgent from './dubbo-agent';
import {ScheduleError, SocketError, ZookeeperTimeoutError} from './err';
import Queue from './queue';
-import {IZkClientProps} from './types';
+import {IDubboResponse, IZkClientProps} from './types';
import {traceErr, traceInfo} from './util';
import {ZkRegistry} from './zookeeper';
@@ -127,7 +127,7 @@
/**
* 处理zookeeper的错误
*/
- private _handleZkClientError = err => {
+ private _handleZkClientError = (err: Error) => {
log(err);
//说明zookeeper连接不上
if (err instanceof ZookeeperTimeoutError) {
@@ -199,11 +199,16 @@
/**
* 当收到数据的时候
*/
- private _handleOnData = ({requestId, res, err}) => {
+ private _handleOnData = ({
+ requestId,
+ res,
+ err,
+ attachments,
+ }: IDubboResponse<any>) => {
if (err) {
- this._queue.failed(requestId, err);
+ this._queue.failed(requestId, err, attachments);
} else {
- this._queue.resolve(requestId, res);
+ this._queue.resolve(requestId, res, attachments);
}
};
diff --git a/packages/dubbo/src/types.ts b/packages/dubbo/src/types.ts
index f1988c9..7bda9a0 100644
--- a/packages/dubbo/src/types.ts
+++ b/packages/dubbo/src/types.ts
@@ -123,6 +123,7 @@
requestId: number;
err: Error | null;
res: T | null;
+ attachments: Object;
}
export interface IHessianType {