R
Railway

✋|help

Prebuilt Mqtt Service and Ports

R--Roy--9/8/2023
Looking for some guidance. Currently have a couple different services in my project, including a postgres db, mqtt broker, a publisher and a subscriber. The mqtt broker service uses an officially hosted docker image. That service internally opens port 1883 for http mqtt communication, 8080 for ws mqtt communication, as well as other ports for misc things like 8888 has routes /health for health check and /status for a management dashboard. Right now only 8080 is exposed via Railways PORT env var and works perfectly for my web socket connections on other services.

Since I can only expose one port via railway does that mean it’s impossible to take advantage of those other pieces? I’m open to any sort of strategy, but don’t know if I could handle modifying the source of the broker itself so would prefer a different option than that

Thanks!
R--Roy--9/8/2023
40a3bc08-0c66-4f5e-a268-736ec53f0cac
Bbrody1929/8/2023
youd need to run a proxy service to map routes to ports on the mqtt service.
this proxy service would be exposed publicly, and proxy incoming requests to the mqtt service via the private network, example:
mqtt-proxy.up.railway.app -> mqtt.railway.internal:1883
mqtt-proxy.up.railway.app/ws -> mqtt.railway.internal:8080
mqtt-proxy.up.railway.app/misc-> mqtt.railway.internal:8888
R--Roy--9/8/2023
Ohh I see, so the internal ports are still available to other services on the network?
Bbrody1929/8/2023
yep, its a private/local network after all
R--Roy--9/8/2023
So I have an express api also running in my project. If I add a route say /mqtt/health. I can make an internal request to the appropriate port and just forward that response?
Bbrody1929/8/2023
yes, but you really should use a proper proxy service like caddy
or nginx if thats more your thing, but i think caddy is far more approachable
R--Roy--9/8/2023
Gotcha thanks for helping me out so quickly. Feel kinda dumb needing to ask that question… lol
Bbrody1929/8/2023
no worries at all
R--Roy--9/8/2023
proxy is pretty easy to see since it’s a private local network
I think I’ll checkout caddy, though nginx is something I do have experience with using before
Bbrody1929/8/2023
caddy is just simpler imo, ive done this with both nginx and caddy, and caddy was the clear winner purely on ease of use and ease of configuration, example
https://github.com/brody192/reverse-proxy/blob/main/Caddyfile
R--Roy--9/8/2023
Gonna check it out right after I finish eating lunch and try deploying it - really appreciate the guidance!
Bbrody1929/8/2023
no problem! if you need help with caddy let me know
R--Roy--9/8/2023
I've got to make a choice. I have an custom domain, my-project.app and right now have railway connected on two difference services to two different subdomains, specifically, mqtt.my-project.app and api.my-project.app. mqtt is going to have a reverse proxy to cover things like / - http, /ws - ws, /health - health check, /admin dashboard, and the api contains the other business logic (mainly uses trpc mounted at /trpc), but will also expose public graphql endpoints for a different piece.

Do you think I'd be doing too much by having a caddy proxy in front of both so that there can continue to be a separation of concerns. Or would it be better to remove the mqtt sub domain entirely and just use one proxy to route all the relevant mqtt requests using a /mqtt/... prefix?
Bbrody1929/8/2023
I don't see why you'd want to put a proxy Infront of your api.
remove any and all public domains from the mqtt service and move them over to the proxy service
R--Roy--9/8/2023
I like that option, it really doesn't need to be in front of the api. So I'll have caddy at mqtt.my-project.app to handle proxying the request to different ports on the mqtt service and I'll keep my standalone api service unaffected.
Thanks again for the direction
Bbrody1929/11/2023
exactly!
id love to hear about the outcome of this!

Looking for more? Join the community!

Recommended Posts
MySQL queries timeout or lead to blank screen on web versionFor the last 2 days or so I've been running into some problems with my personal project database. ItAdonisjs Migration - MySQL using password noTrying to deploy an app on railway with adonisjs and a MySQL database, I can get the web app runningGraalVMHi, is it possible to build a graalvm image in nixpacks? https://github.com/railwayapp/nixpacks/issuDebugging issuesIs their someway to get into filesystem so I can debug production errors a0aaa94d-45ad-410c-bcae-31Debugging issuesIs their somehow to get into file system? or the built filesEnabled mlockHi everyone, I'm currently creating a template for the hashicorp vault service (https://developer.hSubscription already existsI can't enable the developer plan, the system returns the message: "Subscription already exists"simple socket server got timeout errorhi i have a simple question if i have a java simple sever (spring boot) and in my app in another porCheck SuitesI'm looking for a feature that could allow to deploy if failed build So I try to use Check Suites bTypeError: fetch failed error without much description in the logsFull error below: TypeError: fetch failed at Object.fetch (/app/node_modules/next/dist/compiled/unRenamed user/organization for GitHub - unsafe?A student organization I work with has a cron job service for our database, and it's linked with ourContainer Failed to StartError Response from Daemonssh tunneling errorWhen trying to deploy a django project the following error occurs "raise ValueError('No password or Paths not working when deployed to railway but works in local environmentCurrently making a vite/typescript/react project that has working route handling locally but does nopgbouncerHey folks, I have a supabase and Nextjs (+ prisma) project deployed in Railway, what's the best optiAccessing files inside the volumewhat's the best way to export build artifacts from one service to another? during build process, a tHow usage-based resource management works ?Hello, how Railway manages resource scaling ? like how are vCPU and RAM scaled up and down automaticHow to dynamically scale the replicas of an APIs deployed via Railway based on demand?I have API service with a certain number of replicas, whats the recommended way to scale the number Laravel application failed to respondI am unsure what is causing the issue but the after deploying my laravel app, it still does not starRailway credits gone??I had $15.46 in credits, and now $5 is gone. I have a single project, and I know for a fact my proje