marcojulian
Looking for a Change Data Capture (CDC) lib for MySQL
My Elixir application needs to connect with a MySQL database and listen for insert and updates in certain tables, does anyone know about a library that makes this easier? I would use WalEx or Cainophile but they are intended for PostgreSQL DBs.
Marked As Solved
joerichsen
Hi
You could use Port — Elixir v1.20.2 with the stdout option of https://maxwells-daemon.io/
I have this proof of concept code that might get you started
defmodule MaxwellListener do
use GenServer
# Adjust the command to include the full executable path if necessary
@command "maxwell"
@args [
"--user='maxwell'",
"--password='XXXXXX'",
"--host='127.0.0.1'",
"--filter='exclude: *.*, include: holdsport.users, include: holdsport.teams_users'",
"--producer=stdout"
]
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, :ok, opts)
end
def init(:ok) do
command_with_args = Enum.join([@command | @args], " ")
options = [:binary, :exit_status]
port = Port.open({:spawn, command_with_args}, options)
{:ok, %{port: port}}
end
def handle_info({port, {:data, data}}, state) do
process_output(data)
{:noreply, state}
end
def handle_info({:EXIT, _port, _reason}, state) do
# Handle port exit
{:stop, :normal, state}
end
defp process_output(data) do
data
|> String.trim_trailing()
|> Jason.decode!(keys: :atoms)
|> handle()
end
defp handle(%{table: "teams_users", data: %{users_id: user_id}}) do
IO.inspect(user_id, label: "User ID")
end
defp handle(d) do
IO.inspect(d, limit: :infinity)
end
end
1
Last Post!
marcojulian
Popular in Questions
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









