【问题标题】:How to load thrift client in Erlang如何在 Erlang 中加载 Thrift 客户端
【发布时间】:2011-04-30 16:54:36
【问题描述】:

我希望使用 scribe 从 Erlang 应用程序中导出一些数据,但是我在运行 Thrift 客户端时遇到了问题。我在 erlang lib 目录中安装 Thrift。我正在使用:thrift-0.6.1

我找到了一些示例代码,可以通过 thrift 从 erlang 连接到 scribe:

{ok, C} = thrift_client:start_link("localhost", 1463, scribe_thrift, 
                                     [{strict_read, false}, 
                                      {strict_write, false}, 
                                      {framed, true}]),

但 erlang 正在返回此错误:

** exception error: undefined function thrift_client:start_link/4

当我尝试运行 application:start(thrift) 时,我看到了一些 thrift* 的代码完成

7> thrift_client:
   call/3         close/1        module_info/0  module_info/1  new/2          
   send_call/3   

而且没有方法start_link

【问题讨论】:

    标签: erlang thrift scribe


    【解决方案1】:

    我认为这些天你想要像thrift_client_util:new(Host, Port, ProtoModule, Options)这样的东西

    在你的情况下是:

    thrift_client_util:new("localhost", 1463, scribe_thrift,
                           [{strict_read, false}, 
                            {strict_write, false}, 
                            {framed, true}]).
    

    使用 erlang 中的 thrift API 需要牢记的重要一点是,所有调用都会返回一个新的客户端状态值,您必须将其用于后续调用。两次使用客户端状态值会导致哭泣和咬牙切齿。

    【讨论】:

    • 从这个post的回答中观察到返回的客户端状态和原来的一样。
    【解决方案2】:

    几个月前,我将节俭与我的项目整合在一起。获取客户端需要一些初始化步骤。

    {好的,TFactory} = thrift_socket_transport:new_transport_factory( "本地主机", 8899, []), {好的,PFactory} = thrift_binary_protocol:new_protocol_factory(TFactory, []), {ok, 协议} = PFactory(), {ok, Client} = thrift_client:new(Protocol, scribe_thrift),

    有关更多上下文,您可能可以查看我的 git 存储库中的 module

    【讨论】:

    • archaelus 使用 thrift_client_util:new 的回复是这个答案的包装。
    猜你喜欢
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    相关资源
    最近更新 更多