Skip to content

Commit e3aac2d

Browse files
chickenljcarryxyh
authored andcommitted
Fix thrift protocol, use path to locate exporter. (#3331)
* Fix thrift protocol, use path to locate exporter. * Fix UT
1 parent 15faa9b commit e3aac2d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ private Object decode(TProtocol protocol)
163163

164164
// version
165165
String serviceName;
166+
String path;
166167
long id;
167168

168169
TMessage message;
@@ -171,6 +172,7 @@ private Object decode(TProtocol protocol)
171172
protocol.readI16();
172173
protocol.readByte();
173174
serviceName = protocol.readString();
175+
path = protocol.readString();
174176
id = protocol.readI64();
175177
message = protocol.readMessageBegin();
176178
} catch (TException e) {
@@ -181,6 +183,7 @@ private Object decode(TProtocol protocol)
181183

182184
RpcInvocation result = new RpcInvocation();
183185
result.setAttachment(Constants.INTERFACE_KEY, serviceName);
186+
result.setAttachment(Constants.PATH_KEY, path);
184187
result.setMethodName(message.name);
185188

186189
String argsClassName = ExtensionLoader.getExtensionLoader(ClassNameGenerator.class)
@@ -496,6 +499,8 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques
496499
protocol.writeByte(VERSION);
497500
// service name
498501
protocol.writeString(serviceName);
502+
// path
503+
protocol.writeString(inv.getAttachment(Constants.PATH_KEY));
499504
// dubbo request id
500505
protocol.writeI64(request.getId());
501506
protocol.getTransport().flush();

dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftProtocol.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) thro
6363

6464
if (msg instanceof Invocation) {
6565
Invocation inv = (Invocation) msg;
66-
String serviceName = inv.getAttachments().get(Constants.INTERFACE_KEY);
66+
String path = inv.getAttachments().get(Constants.PATH_KEY);
6767
String serviceKey = serviceKey(channel.getLocalAddress().getPort(),
68-
serviceName, null, null);
68+
path, null, null);
6969
DubboExporter<?> exporter = (DubboExporter<?>) exporterMap.get(serviceKey);
7070
if (exporter == null) {
7171
throw new RemotingException(channel,

dubbo-rpc/dubbo-rpc-thrift/src/test/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodecTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public void testEncodeRequest() throws Exception {
9393
Assertions.assertEquals(ThriftCodec.VERSION, protocol.readByte());
9494
// service name
9595
Assertions.assertEquals(Demo.Iface.class.getName(), protocol.readString());
96+
// path
97+
Assertions.assertEquals(Demo.Iface.class.getName(), protocol.readString());
9698
// dubbo request id
9799
Assertions.assertEquals(request.getId(), protocol.readI64());
98100

@@ -148,6 +150,8 @@ public void testDecodeReplyResponse() throws Exception {
148150
protocol.writeI16(Short.MAX_VALUE);
149151
protocol.writeByte(ThriftCodec.VERSION);
150152
protocol.writeString(Demo.Iface.class.getName());
153+
// path
154+
protocol.writeString(Demo.Iface.class.getName());
151155
protocol.writeI64(request.getId());
152156
protocol.getTransport().flush();
153157
headerLength = bos.size();
@@ -221,6 +225,8 @@ public void testDecodeExceptionResponse() throws Exception {
221225
protocol.writeI16(Short.MAX_VALUE);
222226
protocol.writeByte(ThriftCodec.VERSION);
223227
protocol.writeString(Demo.class.getName());
228+
// path
229+
protocol.writeString(Demo.class.getName());
224230
protocol.writeI64(request.getId());
225231
protocol.getTransport().flush();
226232
headerLength = bos.size();
@@ -396,6 +402,9 @@ public void testDecodeRequest() throws Exception {
396402
protocol.writeString(
397403
((RpcInvocation) request.getData())
398404
.getAttachment(Constants.INTERFACE_KEY));
405+
protocol.writeString(
406+
((RpcInvocation) request.getData())
407+
.getAttachment(Constants.PATH_KEY));
399408
protocol.writeI64(request.getId());
400409
protocol.getTransport().flush();
401410
headerLength = bos.size();
@@ -448,6 +457,7 @@ private Request createRequest() {
448457
invocation.setParameterTypes(new Class<?>[]{String.class});
449458

450459
invocation.setAttachment(Constants.INTERFACE_KEY, Demo.Iface.class.getName());
460+
invocation.setAttachment(Constants.PATH_KEY, Demo.Iface.class.getName());
451461

452462
Request request = new Request(1L);
453463

0 commit comments

Comments
 (0)