一个 NettyServer 的 Avro RPC 多个响应者
Avro RPC multiple Responders for one NettyServer
我正在研究 Avro RPC,我正在尝试创建一个简单的示例来更好地理解它。
但我遇到了一个困难:我不能 运行 一个服务器有多个 Responder
,因为 NettyServer 构造函数只允许我使用一个:
public NettyServer(Responder responder, InetSocketAddress addr)
所以,如果我有多个 IDL,像这样:
@namespace("foo.bar")
protocol FooProtocol {
void foo();
}
@namespace("foo.bar")
protocol BarProtocol {
void bar();
}
我无法将两者都添加到我的 NettyServer(因为监听同一个端口):
object FooProtocolImpl : FooProtocol {
override fun foo(): Void? {return null}
}
object BarProtocolImpl : BarProtocol {
override fun bar(): Void? {return null}
}
val server = NettyServer(SpecificResponder(FooProtocol.PROTOCOL, FooProtocolImpl), InnetSocketAddress(9090))
如何将 BarProtocol 添加到我的服务器?如何让这个 NettyServer 对两种协议都有用?
Doug Cutting 在 GrokBase 中的 post 状态:
A separate Responder is currently required for each protocol. If HTTP
is used, different ResponderServlet's can be configured so that
different protocols are run at different URLs. For NettyServer and
SaslSocketServer one must run different protocols on different ports.
Note however that one can create a protocol that's the combination of
several other protocols and serve that. For example, with Java
reflection, if you have Java interface A that's one protocol and Java
interface B that's another then you can implement "interface C extends
A, B" and serve that protocol. Clients that speak either A, B or C
can then connect. A similar effect can be accomplished with Java's
specific compiler by importing various client protocols into the
server's protocol.
因此,另一种方法是创建一个 protocol
,"implements" 您所有的协议,例如:
@namespace("foo.bar")
protocol AllProtocols {
import idl "foo.avdl"
import idl "bar.avdl"
}
并创建实现此协议的 class:
object AllProtocolsImpl : AllProtocols {
override fun foo(): Void? {return null}
override fun bar(): Void? {return null}
}
然后创建服务于此协议的服务器:
val server = NettyServer(SpecificResponder(AllProtocols.PROTOCOL, AllProtocolsImpl), InetSocketAddress(9090))
任何需要 Foo 或 Bar 的客户端都可以连接到此服务器并使用其协议。
我正在研究 Avro RPC,我正在尝试创建一个简单的示例来更好地理解它。
但我遇到了一个困难:我不能 运行 一个服务器有多个 Responder
,因为 NettyServer 构造函数只允许我使用一个:
public NettyServer(Responder responder, InetSocketAddress addr)
所以,如果我有多个 IDL,像这样:
@namespace("foo.bar")
protocol FooProtocol {
void foo();
}
@namespace("foo.bar")
protocol BarProtocol {
void bar();
}
我无法将两者都添加到我的 NettyServer(因为监听同一个端口):
object FooProtocolImpl : FooProtocol {
override fun foo(): Void? {return null}
}
object BarProtocolImpl : BarProtocol {
override fun bar(): Void? {return null}
}
val server = NettyServer(SpecificResponder(FooProtocol.PROTOCOL, FooProtocolImpl), InnetSocketAddress(9090))
如何将 BarProtocol 添加到我的服务器?如何让这个 NettyServer 对两种协议都有用?
Doug Cutting 在 GrokBase 中的 post 状态:
A separate Responder is currently required for each protocol. If HTTP is used, different ResponderServlet's can be configured so that different protocols are run at different URLs. For NettyServer and SaslSocketServer one must run different protocols on different ports.
Note however that one can create a protocol that's the combination of several other protocols and serve that. For example, with Java reflection, if you have Java interface A that's one protocol and Java interface B that's another then you can implement "interface C extends A, B" and serve that protocol. Clients that speak either A, B or C can then connect. A similar effect can be accomplished with Java's specific compiler by importing various client protocols into the server's protocol.
因此,另一种方法是创建一个 protocol
,"implements" 您所有的协议,例如:
@namespace("foo.bar")
protocol AllProtocols {
import idl "foo.avdl"
import idl "bar.avdl"
}
并创建实现此协议的 class:
object AllProtocolsImpl : AllProtocols {
override fun foo(): Void? {return null}
override fun bar(): Void? {return null}
}
然后创建服务于此协议的服务器:
val server = NettyServer(SpecificResponder(AllProtocols.PROTOCOL, AllProtocolsImpl), InetSocketAddress(9090))
任何需要 Foo 或 Bar 的客户端都可以连接到此服务器并使用其协议。