It seems this library is meant for elixir, but I was wondering if we could set this up in phoenix and how? Installing is fine, but where do I call the start_link, subscribe functions to test if I can receive messages?
Sorry very unfamiliar. I read the documentation and there isn’t a handle_info function either. I shouldn’t be sticking any of this receiver / handle_info code in channels correct?
All I’m trying to do is get a golang microservice to tell my phoenix app that my data has been processed and saved to the database. So I understand this to be my phoenix app as the subscriber and my golang microservice to be the publisher
Cool. It sounds like you probably need to create a GenServer process that you add to your application.ex supervision tree. Inside that GenServer you’ll subscribe to RedixPubsub, and then can take some kind of action when a message arrives. I highly recommend checking out this guide https://elixir-lang.org/getting-started/mix-otp/genserver.html and the pages after it if you’re unclear on how to configure a GenServer within your application.
So I’ve just created a MyApp.Registry file (AKA my Genserver) which has a handle_info function. This is located in my folder lib/my_app. What do I do in my application.ex?
defmodule MyApp.Application do
use Application
def start(_type, _args) do
import Supervisor.Spec
children = [
supervisor(MyApp.Repo, []),
supervisor(MyAppWeb.Endpoint, []),
worker(Redix.PubSub, []),
]
{:ok, pubsub} = Redix.PubSub.start_link()
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
result = Supervisor.start_link(children, opts)
result
end
def config_change(changed, _new, removed) do
MyAppWeb.Endpoint.config_change(changed, removed)
:ok
end
end