-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from cabol/1.x.x
Fixed `proplist_to_record` macro, added point_to_point example, fixed version to 1.0.0.
- Loading branch information
Showing
11 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
REBAR = ../../rebar3 | ||
|
||
BUILD_PATH = ./_build/default/lib/*/ebin | ||
|
||
CONFIG ?= config/sys.config | ||
|
||
.PHONY: all compile clean distclean run | ||
|
||
all: compile | ||
|
||
compile: | ||
$(REBAR) compile | ||
|
||
clean: | ||
$(REBAR) clean | ||
|
||
distclean: clean | ||
$(REBAR) clean --all | ||
rm -rf _build *.lock | ||
|
||
run: all | ||
erl -pa $(BUILD_PATH) -s point_to_point -config ${CONFIG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Point-To-Point example | ||
====================== | ||
|
||
To try this example, you need GNU `make` and `git` in your PATH. | ||
|
||
To build the example, run the following command: | ||
|
||
``` bash | ||
$ make | ||
``` | ||
|
||
To start the example: | ||
|
||
``` bash | ||
$ make run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
%% EBus | ||
{ebus, | ||
[ | ||
{pubsub, | ||
[ | ||
{adapter, ebus_ps_pg2}, | ||
{pool_size, 5}, | ||
{name, ebus_ps} | ||
] | ||
} | ||
] | ||
} | ||
]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%% Erlang compiler options | ||
{erl_opts, [debug_info, fail_on_warning]}. | ||
|
||
%% Whether to enable coverage reporting. Default is `false' | ||
{cover_enabled, true}. | ||
|
||
%% Dependencies | ||
{deps, [ | ||
{erlbus, {git, "https://github.com/cabol/erlbus.git", {branch, "master"}}} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
%% Feel free to use, reuse and abuse the code in this file. | ||
|
||
{application, point_to_point, | ||
[ | ||
{description, "ErlBus Point-To-Point example."}, | ||
{vsn, "1"}, | ||
{modules, []}, | ||
{registered, []}, | ||
{applications, | ||
[ | ||
kernel, | ||
stdlib, | ||
ebus | ||
] | ||
}, | ||
{mod, {point_to_point, []}}, | ||
{env, []} | ||
] | ||
}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
%% Feel free to use, reuse and abuse the code in this file. | ||
|
||
-module(point_to_point). | ||
|
||
-behaviour(application). | ||
|
||
%% API. | ||
-export([start/0, start/2]). | ||
-export([stop/0, stop/1]). | ||
|
||
-define(TOPIC, <<"P2P_TOPIC">>). | ||
|
||
%% API. | ||
|
||
start() -> | ||
application:ensure_all_started(point_to_point). | ||
|
||
start(_Type, _Args) -> | ||
P = spawn_link(fun() -> dispatcher(?TOPIC) end), | ||
lists:foreach(fun(N) -> subscriber(?TOPIC, N) end, lists:seq(1, 3)), | ||
timer:sleep(1 * 60 * 1000), | ||
exit(P, kill), | ||
teardown_ebus(). | ||
|
||
stop() -> | ||
application:stop(point_to_point). | ||
|
||
stop(_State) -> | ||
ok. | ||
|
||
%% Internals | ||
|
||
dispatcher(Topic) -> | ||
timer:sleep(500), | ||
Msg = #{topic => Topic, payload => os:timestamp()}, | ||
io:format("Dispatch: ~p~n", [Msg]), | ||
ebus:dispatch(Topic, Msg), | ||
dispatcher(Topic). | ||
|
||
subscriber(Topic, N) -> | ||
Callback = fun(Ctx, Msg) -> | ||
io:format( | ||
"\e[36m---> [PID: ~p][CTX: ~p][MSG: ~p]~n\e[0m", | ||
[self(), Ctx, Msg] | ||
) | ||
end, | ||
{Handler, _} = ebus_process:spawn_handler(Callback, N, [monitor]), | ||
ebus:sub(Handler, Topic). | ||
|
||
teardown_ebus() -> | ||
application:stop(ebus). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters