Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load thrift client in Erlang

I wish to use scribe to export some data from a Erlang application, but I have a problem with running Thrift client. I install Thrift, in the erlang lib directory. I'm using: thrift-0.6.1

I found some example code to connect from erlang via thrift to scribe:

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

but erlang is returning this error:

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

When I try to run application:start(thrift), for a moment I see some code completion for thrift*

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

and there is no method start_link.

like image 476
Michał 'acid' Bagrowski Avatar asked Feb 25 '23 09:02

Michał 'acid' Bagrowski


2 Answers

I think these days you want something like thrift_client_util:new(Host, Port, ProtoModule, Options)

which in your case would be:

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

And an important point to bear in mind with the thrift API in erlang is that all calls return you a new client state value which you must use for subsequent calls. Using a client state value twice leads to wailing and the gnashing of teeth.

like image 68
archaelus Avatar answered Mar 07 '23 16:03

archaelus


I got thrift integrated with my project a couple of months back. There are some initialization steps required to obtain the client.


  {ok, TFactory} = 
    thrift_socket_transport:new_transport_factory(
      "localhost", 8899, []),
  {ok, PFactory} = 
    thrift_binary_protocol:new_protocol_factory(TFactory, []),
  {ok, Protocol} = PFactory(),
  {ok, Client} = thrift_client:new(Protocol, scribe_thrift),

For more context, you can probably take a look at a module from my git repo.

like image 40
arun_suresh Avatar answered Mar 07 '23 18:03

arun_suresh