Merge pull request #60 from poanetwork/ferigis.59.migrate_to_messagepack
[#59] migrate to message pack
This commit is contained in:
commit
cfbe423e25
|
@ -52,7 +52,7 @@ mix dialyzer
|
|||
To build an executable you'll need Elixir 1.6 (and Erlang/OTP 20).
|
||||
|
||||
1. Once you have a copy of this repository configure the agent for production in the file `config/prod.exs`.
|
||||
2. An example configuration can be found in `config/test.exs`.
|
||||
2. An real configuration example can be found in the default `config/prod.exs`.
|
||||
3. Do a `mix deps.get` to fetch, among other dependencies, the tooling for building server executables.
|
||||
4. A `env MIX_ENV=prod mix release --name=poa_agent --env=prod` will assemble an executable.
|
||||
|
||||
|
|
|
@ -1 +1,40 @@
|
|||
use Mix.Config
|
||||
|
||||
config :poa_agent,
|
||||
transfer_config_overlay: "config/transfer_overlay.json"
|
||||
|
||||
config :ethereumex,
|
||||
url: "http://localhost:8545"
|
||||
|
||||
# configuration for collectors. The format for each collector is {collector_process_id, module, label, args}
|
||||
config :poa_agent,
|
||||
:collectors,
|
||||
[
|
||||
{:eth_information, POAAgent.Plugins.Collectors.Eth.Information, 60_000, :eth_information, [url: "http://localhost:8545", name: "Elixir-NodeJS-Integration", contact: "myemail@gmail.com"]},
|
||||
{:eth_latest_block, POAAgent.Plugins.Collectors.Eth.LatestBlock, 500, :latest_block, [url: "http://localhost:8545"]},
|
||||
{:eth_stats, POAAgent.Plugins.Collectors.Eth.Stats, 5000, :eth_stats, [url: "http://localhost:8545"]},
|
||||
{:eth_pending, POAAgent.Plugins.Collectors.Eth.Pending, 500, :eth_pending, [url: "http://localhost:8545"]}
|
||||
|
||||
]
|
||||
|
||||
# configuration for transfers. The format for each collector is {collector_process_id, module, args}
|
||||
config :poa_agent,
|
||||
:transfers,
|
||||
[
|
||||
{:rest_transfer, POAAgent.Plugins.Transfers.HTTP.REST, [
|
||||
address: "http://localhost:4002",
|
||||
identifier: "elixirNodeJSIntegration",
|
||||
secret: "mysecret"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
# configuration for mappings. This relates one collector with a list of transfers which the data will be sent
|
||||
config :poa_agent,
|
||||
:mappings,
|
||||
[
|
||||
{:eth_latest_block, [:rest_transfer]},
|
||||
{:eth_stats, [:rest_transfer]},
|
||||
{:eth_pending, [:rest_transfer]},
|
||||
{:eth_information, [:rest_transfer]}
|
||||
]
|
||||
|
|
|
@ -56,7 +56,7 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
|
|||
event = %{}
|
||||
|> Map.put(:id, state.identifier)
|
||||
|> Map.put(:secret, state.secret)
|
||||
|> Jason.encode!()
|
||||
|> Msgpax.pack!()
|
||||
|
||||
before_ping = POAAgent.Utils.system_time()
|
||||
|
||||
|
@ -96,13 +96,13 @@ defmodule POAAgent.Plugins.Transfers.HTTP.REST do
|
|||
|> Map.put(:secret, state.secret)
|
||||
|> Map.put(:type, "ethereum_metrics") # for now only ethereum_metrics
|
||||
|> Map.put(:data, data)
|
||||
|> Jason.encode!()
|
||||
|> Msgpax.pack!()
|
||||
|
||||
post(state.address <> url, event)
|
||||
end
|
||||
|
||||
defp post(address, event) do
|
||||
HTTPoison.post(address, event, [{"Content-Type", "application/json"}])
|
||||
HTTPoison.post(address, event, [{"Content-Type", "application/msgpack"}])
|
||||
end
|
||||
|
||||
defp set_ping_timer() do
|
||||
|
|
1
mix.exs
1
mix.exs
|
@ -31,6 +31,7 @@ defmodule POAAgent.MixProject do
|
|||
[
|
||||
{:ethereumex, "~> 0.3"},
|
||||
{:poison, "~> 3.1"},
|
||||
{:msgpax, "~> 2.1"},
|
||||
|
||||
# Tests
|
||||
{:credo, "~> 0.9", only: [:dev, :test], runtime: false},
|
||||
|
|
1
mix.lock
1
mix.lock
|
@ -19,6 +19,7 @@
|
|||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
|
||||
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"},
|
||||
"mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"msgpax": {:hex, :msgpax, "2.1.1", "833bc9ce6d3e073cf966fec94d3f976ca7100685b4f0efb6e30ef512f2e8a4d7", [], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"},
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
|
||||
|
|
|
@ -15,6 +15,7 @@ defmodule POAAgent.Transfers.RestTest do
|
|||
[],
|
||||
[
|
||||
post: fn(url, event, _) ->
|
||||
{:ok, event} = Msgpax.unpack(event)
|
||||
send(test_pid, {url, event})
|
||||
{:ok, %HTTPoison.Response{status_code: 200}}
|
||||
end
|
||||
|
@ -29,7 +30,10 @@ defmodule POAAgent.Transfers.RestTest do
|
|||
]}]) do
|
||||
{:ok, _pid} = REST.start_link(args)
|
||||
|
||||
assert_receive {"localhost/data", "{\"data\":{\"body\":{\"latency\"" <> _}, 20_000
|
||||
assert_receive {"localhost/data", %{"data" => %{"body" => body}}}, 20_000
|
||||
|
||||
assert Map.has_key?(body, "latency")
|
||||
|
||||
assert_receive {"localhost/ping", _}, 20_000
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue