0

My goal of test module is to start storing data that I input on my own in my local node.

I have set up a local node on my computer. I also attached a new erlang module to it via riak attach.

In my module test.erl there is only riakConnect function so far:

riakConnect() ->
  riakc_pb_socket:start_link("127.0.0.1", 8087).

I also have a receive part in the same module which looks similar to (now its commented out):

riakReceive() ->
  receive
     {store, Bucket, Key, Value} ->
         ...
  end.

The problem is that when I attach the file, I get to the node's console which says that riakc_pb_socket:start_link() is undefined and actually nothing reacts in there.

I assume I am missing some information here.

Gabriele
  • 25
  • 8

1 Answers1

1

Are you running your node with riakc_pb_socket in your path? If you look into repo's readme you have to start your VM with compiled erlang binary files added to erl path

$ erl -pa $PATH_TO_RIAKC/ebin $PATH_TO_RIAKC/deps/*/ebin

If you are in you Erlang shell you can verify that you are able to load module with l(ModuleName). function. And you could check your path (where to look for binaries) with code:get_path().. You also could modify it (add new directories) but as general rule you should have correct VM starting script/command.

And finally, if you developing your own application (which i think you are) you could look into tools like rebar. There you could describe all your dependencies, like you erlang-riak client, and he will help you with downloading and compiling them. With this you could strart your VM with simple

erl -pa ebin -pa deps/*/ebin

EDIT after comments

Riak is just another application, and with Erlang you actually can connect wright into it. Just inside working production stuff. But this is quite dangerous, or it could be. You should leave Riak be. At least it internals. Especially that Riak gives you good stable interface to connect to it form outside.

So lets do just that that. We will live your Riaks nodes running, and write yet another application that will "speak" to it. And to do speaking we will use riak-erlang client from basho itself.

First step is creating development environment with use of rebar build tool. Fallowing getting started guide

$ mkdir myapp
$ cd myapp
$ wget https://raw.github.com/wiki/rebar/rebar/rebar && chmod u+x rebar
$ rebar create-app appid=myapp

Other then few other files you now have src folder where you can (and will) put your custom modules. You can check if it compiles with ./rebar compile command. All compiled files will be in bin folder (same level as src) and will have .beam extension (just like java have .java).

Next thing we need is accual library. We need riakc_pb_socket.beam to run anything from riakc_pb_socket module. Easiest way to do that is download sources and compile them. And it is quite easy since we use rebar for building stuff.

We gonna create rebar.config file and populate it with dependency

{deps, [{ riakc, ".*" ,
          {git, "https://github.com/basho/riak-erlang-client.git", {branch, "1."}}}
       ]}.

and download and compile those with

$ ./rebar get-deps compile

And now you should be able to start new Erlang VM, give it a name, add path to your bineries (from custom modules, and dependencies) and from shell run your code.

$ erl -sname myapp -pa ebin -pa deps/*/ebin 
(myapp@localhost) 1> custom_module:riakConnect().

and it should just pass.

If you would like to just run some code straight from system console look into erl -run or escript.

And that should get you going.

mpm
  • 3,534
  • 23
  • 33
  • if I run riak attach I get into erlang shell which says: (riak@127.0.0.1) 1> Which means I am already in the shell. I still have no clue on how to use riak client library in there. I just tried writing riakConnect() -> riak:connect('127.0.0.1'). and I got {ok, {riak_client, ['riak@local', undefined]}]} – Gabriele Oct 24 '14 at 21:34
  • I will add some things to my answer. Do you have any Java (or any programming) experience? I'm just trying to establish to what I could compare your use case. – mpm Oct 24 '14 at 21:49
  • And again what is your use case? Do you need Erlang application that will interact with Riak, or do you want to tinker with Riak from inside, or do you just need to populate Riak with some data? – mpm Oct 24 '14 at 21:51
  • Yes, I know Java. Quick question. So if I started erk vm via erlang client, does it mean that all I have to do is just specify my local riak's IP with port and thats all? Then it would know where to store everything. – Gabriele Oct 24 '14 at 21:51
  • For now I just want to enter manual data (using io:get_line) into Riak via my own module. – Gabriele Oct 24 '14 at 21:52
  • Thank you! What would be a simple template for storing data in Riak though? I make a connection to riak via riak_pb_socket:start_link(), then every time I want to enter something, I should spawn a process to store it? – Gabriele Oct 24 '14 at 22:46
  • I wouldn't think spawning a process for every data element is necessary. Other than that just fallow https://github.com/basho/riak-erlang-client/#storing-new-data – mpm Oct 24 '14 at 23:35
  • I have already read it, but Im trying to put everything into a nice module and Im doing some major mistakes. – Gabriele Oct 24 '14 at 23:52
  • You would have to share some code; whats working, whats not. Maybe even another question. – mpm Oct 24 '14 at 23:58
  • When I take care of syntax errors, I always get that variables 'Bucket' and 'InsertData' are unbound. – Gabriele Oct 25 '14 at 00:31