gmtprime / yggdrasil Goto Github PK
View Code? Open in Web Editor NEWSubscription and publishing server for Elixir applications.
License: MIT License
Subscription and publishing server for Elixir applications.
License: MIT License
config/dev.exs
config :yggdrasil,
rabbitmq: [host: "127.0.0.1",
port: 5672,
username: "dwalin",
password: "dwalin",
virtual_host: "/"]
iex -S mix
iex(1)> Application.ensure_started(:yggdrasil)
:ok
iex(2)> Application.ensure_started(:dwalin)
:ok
channel = %Yggdrasil.Channel{channel: "example", decoder: Yggdrasil.Decoder.Default.RabbitMQ}
Yggdrasil.subscribe(channel)
[debug] Started publisher for %Yggdrasil.Channel{channel: "example", decoder: Yggdrasil.Decoder.Default.RabbitMQ}.
** (exit) exited in: GenServer.call(Yggdrasil.Broker, {:subscribe, %Yggdrasil.Channel{channel: "example", decoder: Yggdrasil.Decoder.Default.RabbitMQ}, #PID<0.264.0>}, 5000)
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, {:shutdown, {:failed_to_start_child, Yggdrasil.Adapter.RabbitMQ, {:function_clause, [{Yggdrasil.Adapter.RabbitMQ, :init, [%Yggdrasil.Adapter{channel: "example", publisher: {:via, ExReg, {Yggdrasil.Publisher, "example", Yggdrasil.Decoder.Default.RabbitMQ}}}], [file: 'lib/yggdrasil/adapter/rabbitmq.ex', line: 28]}, {Connection, :init_it, 6, [file: 'lib/connection.ex', line: 424]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}}}}
(yggdrasil) lib/yggdrasil/publisher/generator.ex:40: Yggdrasil.Publisher.Generator.start_publisher/2
(yggdrasil) lib/yggdrasil/broker.ex:198: Yggdrasil.Broker.do_subscribe/3
(yggdrasil) lib/yggdrasil/broker.ex:303: Yggdrasil.Broker.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
[error] GenServer Yggdrasil.Broker terminating
** (MatchError) no match of right hand side value: {:error, {:shutdown, {:failed_to_start_child, Yggdrasil.Adapter.RabbitMQ, {:function_clause, [{Yggdrasil.Adapter.RabbitMQ, :init, [%Yggdrasil.Adapter{channel: "example", publisher: {:via, ExReg, {Yggdrasil.Publisher, "example", Yggdrasil.Decoder.Default.RabbitMQ}}}], [file: 'lib/yggdrasil/adapter/rabbitmq.ex', line: 28]}, {Connection, :init_it, 6, [file: 'lib/connection.ex', line: 424]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}}}}
(yggdrasil) lib/yggdrasil/publisher/generator.ex:40: Yggdrasil.Publisher.Generator.start_publisher/2
(yggdrasil) lib/yggdrasil/broker.ex:198: Yggdrasil.Broker.do_subscribe/3
(yggdrasil) lib/yggdrasil/broker.ex:303: Yggdrasil.Broker.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {:subscribe, %Yggdrasil.Channel{channel: "example", decoder: Yggdrasil.Decoder.Default.RabbitMQ}, #PID<0.264.0>}
State: %Yggdrasil.Broker{generator: Yggdrasil.Publisher.Generator, monitors: 94246, subscribers: 98343}
(elixir) lib/gen_server.ex:604: GenServer.call/3
(yggdrasil) lib/yggdrasil/backend.ex:55: Yggdrasil.Backend.join/2
The PostgreSQL adapter handles the disconnection correctly, but does not send the {:Y_DISCONNECTED, _}
message to its subscribers. Additionally, there is no exponential backoff in the adapter.
I use {:phoenix, "~> 1.6.6"}
with project[:elixir] = 1.13
and {:yggdrasil, "~> 6.0"}
and config :yggdrasil, postgres: [hostname: "localhost"]
I tested the "pg_notify" example:
iex> Yggdrasil.subscribe(name: "new_books", adapter: :postgres, transformer: :json)
{:error, "Yggdrasil postgres not registered in any node"}
If I declare {yggdrasil, "~> 5.0"}
, then I have a dependency problem. The command mix deps.get
returns:
Failed to use "phoenix_pubsub" (version 2.0.0) because
phoenix (version 1.6.6) requires ~> 2.0
yggdrasil (versions 5.0.1 and 5.0.2) requires ~> 1.1
I tested that the trigger worked with Postgrex.Notification
using this setup:
# when I notify in a psql session:
yggdrasil_pg_notify=# NOTIFY "new books", '{"id": 1, "title": "one"}';
# the iex responds with:
iex(2)> [info] [id: 1, title: "one"]
Redis adapter is not informing its subscribers of disconnections, though it handles the disconnections correctly. Additionally, the backoff should be exponential and not 5 seconds.
If I try to use the first example from the README:
Yggdrasil.Feed.subscribe Yggdrasil.Feed,
Yggdrasil.Broker.Redis,
"trees",
&(IO.puts "#{inspect &1}")
I get this error:
** (exit) exited in: GenServer.call(Yggdrasil.Feed, {:subscribe, Yggdrasil.Broker.Redis, "trees"}, 5000)
** (EXIT) no process
(elixir) lib/gen_server.ex:596: GenServer.call/3
lib/yggdrasil/feed.ex:32: Yggdrasil.Feed.subscribe/4
Can you please add some more information to the README, how to use this library? The examples look quite useful, but I can't get them working.
Installed Elxir:
$ elixir --version
Erlang/OTP 19 [erts-8.0.2] [source-9503fff] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.3.2
Hi!
Very very very awesome project!
One missing piece of functionality(that i can open a PR for assuming it makes sense) - How can i send rabbitmq options(the 5th param to AMQP.Basic.publish) - that can include headers etc..
Maybe a general options param to publish can be added that each adapter can do whatever he wants with?
Maybe the message encoder can do more and extract headers?
What do you think
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.