I have an unusual question that is how to start phoenix server without actually listening at any ip address or port.
The reason is that my app will have two major functional blocks, one is as REST and socket api server. Another one is to listen to events from other applications, do some processing and publish the some data to FE socket via phoenix socket channels. I wish to be able to start one node as api server, another node as event listening, processing and publishing server that will join the cluster of api servers but doesn’t listen to any ip address thus not to expose itself.
I don’t think that this is possible because the “phoenix server” is a http server that expects http requeststo reply to.
But you can skip the endpoint from your supervisor children in your application.ex. The endpoint will not be started but that does not prevent you to listen or publish to your pubsub! (I believe so, the pubsub is independant by now, but I remember using the broadcast functions required an endpoint, but now I see it takes the pubsub name so all good I guess).
See the Runtime Configuration section of the Phoenix.Endpoint docs. You can set server: false.
:server - when true, starts the web server when the endpoint supervision tree starts. Defaults to false. The mix phx.server task automatically sets this to true
The server is actually off by default unless you use the special mix phx.server command which enables it. That’s why you have to pass PHX_SERVER=true for a release (where there’s no mix), which the generated scripts will do for you.
Another thing you can do is to simply listen on a UNIX domain socket. This way you can have a uniform starting strategy and a load balancer in front of your service can direct traffic to one of the sockets.