Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4177245

Browse files
committed
Merge pull request linkerd#115 from liamstewart/ls/thrift_compact_protocol
Protocol configuration for thrift client/server.
2 parents 7ae936c + f6304d3 commit 4177245

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 0.1.1
22

3+
* New `thriftProtocol` config option to the thrift protocol to be
4+
specified.
5+
36
## 0.1.0
47

58
* Introduce Marathon-backed service discovery, for routing traffic in Mesos.

docs/config.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ Thrift servers define additional parameters:
246246
* *thriftFramed* -- if `true`, a framed thrift transport is used for incoming
247247
requests; otherwise, a buffered transport is used. Typically this setting
248248
matches the router's `thriftFramed` param. (default: true)
249+
* *thriftProtocol* -- allows the thrift protocol to be chosen;
250+
currently supports 'binary' for `TBinaryProtocol` (default) and
251+
'compact' for `TCompactProtocol`. Typically this setting matches
252+
the router's client `thriftProtocol` param.
249253

250254
The default server _port_ is 4114.
251255

@@ -254,9 +258,13 @@ Thrift also supports additional *client* parameters:
254258
* *thriftFramed* -- if `true`, a framed thrift transport is used for outgoing
255259
requests; otherwise, a buffered transport is used. Typically this setting
256260
matches the router's servers' `thriftFramed` param. (default: true)
261+
* *thriftProtocol* -- allows the thrift protocol to be chosen;
262+
currently supports `binary` for `TBinaryProtocol` (default) and
263+
`compact` for `TCompactProtocol`. Typically this setting matches
264+
the router's servers' `thriftProtocol` param.
257265

258266
As an example: Here's a thrift router configuration that routes thrift--via
259-
buffered transport--from port 4004 to port 5005
267+
buffered transport using the TCompactProtocol --from port 4004 to port 5005
260268

261269
```yaml
262270
routers:
@@ -268,8 +276,10 @@ routers:
268276
- port: 4004
269277
ip: 0.0.0.0
270278
thriftFramed: false
279+
thriftProtocol: compact
271280
client:
272281
thriftFramed: false
282+
thriftProtocol: compact
273283
```
274284

275285
<a name="protocol-mux"></a>

linkerd/protocol/thrift/src/main/scala/io/buoyant/linkerd/protocol/ThriftInitializer.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package protocol
33

44
import com.twitter.finagle.Path
55
import com.twitter.finagle.Thrift.param
6+
import com.twitter.finagle.thrift.Protocols
67
import io.buoyant.router.{Thrift, RoutingFactory}
8+
import org.apache.thrift.protocol.TCompactProtocol
79

810
class ThriftInitializer extends ProtocolInitializer {
911
val name = "thrift"
@@ -28,7 +30,16 @@ class ThriftInitializer extends ProtocolInitializer {
2830
Thrift.param.MethodInDst(methodInDst)
2931
}
3032

33+
val Protocol = Parsing.Param.Text("thriftProtocol") { protocol =>
34+
val factory = protocol match {
35+
case "binary" => Protocols.binaryFactory()
36+
case "compact" => new TCompactProtocol.Factory()
37+
case _ => throw new IllegalArgumentException(s"unsupported thrift protocol $protocol")
38+
}
39+
param.ProtocolFactory(factory)
40+
}
41+
3142
override val routerParamsParser = MethodInDst
32-
override val serverParamsParser = Framed
33-
override val clientParamsParser = Framed
43+
override val serverParamsParser = Framed.andThen(Protocol)
44+
override val clientParamsParser = Framed.andThen(Protocol)
3445
}

0 commit comments

Comments
 (0)