| | |
| | | %% API |
| | | -export([init/0]). |
| | | |
| | | %%-include_lib("eunit/include/eunit.hrl"). |
| | | %%-include("../priv/mongodb-erlang/include/mongo_protocol.hrl"). |
| | | |
| | | %-include("/Users/bin.shen/git/rabbitmq-erlang-client/include/amqp_client.hrl"). |
| | | |
| | | |
| | | init() -> |
| | | A = <<1,2>>, |
| | | B = <<3,4,5>>, |
| | | C = <<A/binary, B/binary>>, |
| | | io:format("~p~n", [C]). |
| | | %% A = <<1,2>>, |
| | | %% B = <<3,4,5>>, |
| | | %% C = <<A/binary, B/binary>>, |
| | | %% io:format("~p~n", [C]){port, 27017}, |
| | | |
| | | %% application:ensure_all_started(mongodb), |
| | | |
| | | |
| | | application:start (bson), |
| | | application:start (crypto), |
| | | application:start (poolboy), |
| | | application:start (mongodb), |
| | | |
| | | |
| | | %% Database = <<"test1">>, |
| | | %% {ok, Connection} = mc_worker_api:connect ([{database, Database}]), |
| | | %% io:format("Connection ~p~n", [Connection]), |
| | | %% |
| | | %% Collection = <<"test2">>, |
| | | %% mc_worker_api:insert(Connection, Collection, [ |
| | | %% {<<"name">>, <<"Yankees">>, <<"home">>, {<<"city">>, <<"New York">>, <<"state">>, <<"NY">>}, <<"league">>, <<"American">>}, |
| | | %% {<<"name">>, <<"Mets">>, <<"home">>, {<<"city">>, <<"New York">>, <<"state">>, <<"NY">>}, <<"league">>, <<"National">>}, |
| | | %% {<<"name">>, <<"Phillies">>, <<"home">>, {<<"city">>, <<"Philadelphia">>, <<"state">>, <<"PA">>}, <<"league">>, <<"National">>}, |
| | | %% {<<"name">>, <<"Red Sox">>, <<"home">>, {<<"city">>, <<"Boston">>, <<"state">>, <<"MA">>}, <<"league">>, <<"American">>} |
| | | %% ]), |
| | | |
| | | %% Database = <<"test1">>, |
| | | %% case mc_worker_api:connect([ |
| | | %% {database, Database}, |
| | | %% {host, "127.0.0.1"}, |
| | | %% {port, 27017} |
| | | %% ]) of |
| | | %% {ok, Connection} -> |
| | | %% io:format("Connection ~p~n", [Connection]), |
| | | %% |
| | | %% Cursor = mc_worker_api:find(Connection, <<"test2">>, {}), |
| | | %% io:format("~p cursor: ~p~n", [self(), Cursor]), |
| | | %% mc_cursor:close(Cursor); |
| | | %% |
| | | %% {error, Reason} -> |
| | | %% io:format("unable to connect to ~p: ~p~n", [Database, Reason]) |
| | | %% end, |
| | | |
| | | {ok, Connection} = mc_worker_api:connect([ |
| | | {database, <<"moral_db">>}, |
| | | {login, <<"moral_user">>}, |
| | | {password, <<"m2o0r1a6l_passw0rd">>}, |
| | | {host, "121.40.92.176"}, |
| | | {port, 27017} |
| | | ]), |
| | | |
| | | io:format("Connection is XXX : ~p~n", [Connection]), |
| | | io:format("*****************###"), |
| | | |
| | | mc_worker_api:insert(Connection, <<"alerts">>, [ |
| | | {<<"mac">>, <<"accf23b87fbf">>, <<"x1">>, <<"1">>, <<"x2">>, <<"2">>} |
| | | ]), |
| | | |
| | | %% Cursor = mc_worker_api:find_one(Connection, <<"test2">>, {}), |
| | | |
| | | |
| | | %% Cursor = mc_worker_api:find(Connection, <<"alerts">>, {}), |
| | | %% Result = mc_cursor:rest(Cursor), |
| | | %% io:format("~p~n", [Result]), |
| | | %% mc_cursor:close(Cursor), |
| | | %% mc_worker_api:disconnect(Connection), |
| | | |
| | | %%process({}) -> |
| | | %% ok; |
| | | %% |
| | | %%process(Cursor) -> |
| | | %% io:format("----Cursor:~p~n", [Cursor]), |
| | | %% Record = mc_worker_api:(Cursor), |
| | | %% io:format("Record:~p~n", [Record]), |
| | | %% case Record of |
| | | %% {} -> |
| | | %% no_more; |
| | | %% _ -> |
| | | %% process(Cursor) |
| | | %% end, |
| | | |
| | | %% {ok, Connection} = amqp_connection:start(#amqp_params_network{}), |
| | | %% %% Open a channel on the connection |
| | | %% {ok, Channel} = amqp_connection:open_channel(Connection), |
| | | |
| | | %% %% Declare a queue |
| | | %% #'queue.declare_ok'{queue = Q} = amqp_channel:call(Channel, #'queue.declare'{}), |
| | | %% |
| | | %% %% Publish a message |
| | | %% Payload = <<"foobar">>, |
| | | %% Publish = #'basic.publish'{exchange = <<>>, routing_key = Q}, |
| | | %% amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}), |
| | | %% |
| | | %% %% Get the message back from the queue |
| | | %% Get = #'basic.get'{queue = Q}, |
| | | %% {#'basic.get_ok'{delivery_tag = Tag}, Content} |
| | | %% = amqp_channel:call(Channel, Get), |
| | | %% |
| | | %% %% Do something with the message payload |
| | | %% %% (some work here) |
| | | %% |
| | | %% %% Ack the message |
| | | %% amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}), |
| | | %% |
| | | %% %% Close the channel |
| | | %% amqp_channel:close(Channel), |
| | | %% %% Close the connection |
| | | %% amqp_connection:close(Connection), |
| | | |
| | | %% application:start(emongo), |
| | | %% emongo:add_pool(pool1, "192.168.1.102", 27017, "test1", 1), |
| | | %% emongo:insert(pool1, "test2", {name:2334}), |
| | | |
| | | io:format("*****************###"), |
| | | |
| | | ok. |