R
Railway•5mo ago
Muijf

how to I connect to a rabbitmq service internally?

I can't seem to connect.
90 Replies
Percy
Percy•5mo ago
Project ID: 691265c1-a324-4034-8288-642c7ab38ebc
Muijf
Muijf•5mo ago
691265c1-a324-4034-8288-642c7ab38ebc I am using amqp://<user>:<password>@rabbitmq.railway.internal:5672 from another service.
Brody
Brody•5mo ago
what specific error do you get?
Muijf
Muijf•5mo ago
Just error. NestJS doesn't seem to give much more But it works locally. I am sure it just doesn't connect
Brody
Brody•5mo ago
send it anyway? lol
Muijf
Muijf•5mo ago
error

url: "amqp://<user>:<password>@rabbitmq.railway.internal:5672"
error

url: "amqp://<user>:<password>@rabbitmq.railway.internal:5672"
Brody
Brody•5mo ago
oh wow you weren't kidding when you said "just error"
Muijf
Muijf•5mo ago
yup
Brody
Brody•5mo ago
I assume you can connect just fine when on railway if you where to swap to the public url?
Muijf
Muijf•5mo ago
If I open a tcp proxy and use that? I can try
Brody
Brody•5mo ago
yes please do
Muijf
Muijf•5mo ago
Deploying right now, 1 sec No I can't use the public uri either apparently
Brody
Brody•5mo ago
same vague error?
Muijf
Muijf•5mo ago
Yes
Brody
Brody•5mo ago
now you say it works locally, that means you are running rabbitmq locally too?
Muijf
Muijf•5mo ago
Yes Using a dev container and docker compose with the same docker image for rabbitmq and environment variables too
Brody
Brody•5mo ago
same image running locally as you run on railway?
Muijf
Muijf•5mo ago
Yes
Brody
Brody•5mo ago
can you run your app locally but connect to the rabbitmq hosted on railway?
Muijf
Muijf•5mo ago
I'll get back to you on that in 15 mins, quick break
Brody
Brody•5mo ago
sounds good
Muijf
Muijf•5mo ago
Doesn't seem to work either.. I can't seem to figure out why
Brody
Brody•5mo ago
same error?
Muijf
Muijf•5mo ago
Yes Tried everything, not sure
Brody
Brody•5mo ago
can you send the logs from your rabbitmq service? https://bookmarklets.up.railway.app/log-downloader/
Brody
Brody•5mo ago
its in the active state right?
Muijf
Muijf•5mo ago
yes
Brody
Brody•5mo ago
are you deploying from an image or a repo, i know you said image but people have said image before when they meant repo
Muijf
Muijf•5mo ago
Repo > Dockerfile
Brody
Brody•5mo ago
yeah gotcha, not a direct image deploy
Muijf
Muijf•5mo ago
yes
Brody
Brody•5mo ago
are you using the rabbitmq template?
Muijf
Muijf•5mo ago
I do kinda, but only kept the base image. I removed the quickstart
Brody
Brody•5mo ago
show me how you run rabbitmq locally?
Muijf
Muijf•5mo ago
Dockerfile
FROM rabbitmq:management-alpine

ARG RABBITMQ_DEFAULT_USER RABBITMQ_DEFAULT_PASS RABBITMQ_DEFAULT_VHOST

COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
FROM rabbitmq:management-alpine

ARG RABBITMQ_DEFAULT_USER RABBITMQ_DEFAULT_PASS RABBITMQ_DEFAULT_VHOST

COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
same as with the template. docker-compose.yml
rabbitmq:
build: ../infrastructure/rabbitmq
environment:
RABBITMQ_DEFAULT_USER: app
RABBITMQ_DEFAULT_PASS: app
ports:
- 15672:15672
networks:
- app
rabbitmq:
build: ../infrastructure/rabbitmq
environment:
RABBITMQ_DEFAULT_USER: app
RABBITMQ_DEFAULT_PASS: app
ports:
- 15672:15672
networks:
- app
run within a dev container
Brody
Brody•5mo ago
show me your in code client?
Muijf
Muijf•5mo ago
InternalAccountsModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
rabbitMqUrl: configService.getOrThrow<string>('RABBITMQ_URL'),
}),
inject: [ConfigService],
}),
InternalAccountsModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
rabbitMqUrl: configService.getOrThrow<string>('RABBITMQ_URL'),
}),
inject: [ConfigService],
}),
constructor(@Inject(MODULE_OPTIONS_TOKEN) options: AccountsModuleOptions) {
this.client = ClientProxyFactory.create({
transport: Transport.RMQ,
options: {
urls: [options.rabbitMqUrl],
queue: 'accounts',
noAck: true,
},
})
}
constructor(@Inject(MODULE_OPTIONS_TOKEN) options: AccountsModuleOptions) {
this.client = ClientProxyFactory.create({
transport: Transport.RMQ,
options: {
urls: [options.rabbitMqUrl],
queue: 'accounts',
noAck: true,
},
})
}
chirag
chirag•5mo ago
make sure to set ENABLE_ALPINE_PRIVATE_NETWORKING=TRUE in environment variables if you are using alpine image so you can access internal services
Brody
Brody•5mo ago
they cant even connect to the public url of rabbitmq locally
Muijf
Muijf•5mo ago
only variable is that I am using Bun. But I can connect locally using bun runtime so it shouldn't really make a difference. It could though So that variable should be set in the rabbitmq env?
Brody
Brody•5mo ago
you can connect to rabbitmq thats hosted on railway from your locally running app?
Muijf
Muijf•5mo ago
I can't I can connect to my local rabbitmq using bun runtime
chirag
chirag•5mo ago
i dont know how tcp proxy works but i think you also need to make sure the service listens on ipv6 address too
Brody
Brody•5mo ago
nope the public tcp proxy is ipv4
chirag
chirag•5mo ago
the internal one is ipv6
Brody
Brody•5mo ago
i am aware, but they cant use either
chirag
chirag•5mo ago
if you are using template then i dont think you need to change anything make sure to wait >100ms before connecting because private network takes time to be available
Brody
Brody•5mo ago
they cant connect to it locally, please read through this thread
Muijf
Muijf•5mo ago
I am. It's been up for hours locally within the internal network is what I want. But yes, I can't even connect locally using a public tcp tunnel
Brody
Brody•5mo ago
update: i can
Brody
Brody•5mo ago
No description
No description
Muijf
Muijf•5mo ago
So it must be bun
Brody
Brody•5mo ago
thats what im thinking too but use this url amqp://brody:brody@monorail.proxy.rlwy.net:59808 to run a connect test locally
Muijf
Muijf•5mo ago
That works, using the same environment as before So I am doing something wrong then
Brody
Brody•5mo ago
what is your public url you are testing with and please do yourself a favor, remove the repo from the service and deploy directly from the image rabbitmq:management-alpine (like i have)
Muijf
Muijf•5mo ago
Sure let me try that. That's the only difference right now I think
Brody
Brody•5mo ago
want me to make a new template that deploys from an image and has all the needed variables preconfigured like a RABBITMQ_URL and RABBITMQ_PRIVATE_URL?
Muijf
Muijf•5mo ago
Nah it's okay I am doing that right now
Brody
Brody•5mo ago
i mean id still like to so i know its done correctly
Muijf
Muijf•5mo ago
Got it working So the issue was either the username or password was too long. But there was no error and I didn't even know that was possible Using simple user and pass like app:app works my username and passwords were no more than 16 chars
RABBITMQ_DEFAULT_PASS=app
RABBITMQ_DEFAULT_USER=app
RABBITMQ_PRIVATE_URL=amqp://${{RABBITMQ_DEFAULT_USER}}:${{RABBITMQ_DEFAULT_PASS}}@${{RAILWAY_PRIVATE_DOMAIN}}:5672
RABBITMQ_URL=amqp://${{RABBITMQ_DEFAULT_USER}}:${{RABBITMQ_DEFAULT_PASS}}@${{RAILWAY_TCP_PROXY_DOMAIN}}:${{RAILWAY_TCP_PROXY_PORT}}
RABBITMQ_DEFAULT_PASS=app
RABBITMQ_DEFAULT_USER=app
RABBITMQ_PRIVATE_URL=amqp://${{RABBITMQ_DEFAULT_USER}}:${{RABBITMQ_DEFAULT_PASS}}@${{RAILWAY_PRIVATE_DOMAIN}}:5672
RABBITMQ_URL=amqp://${{RABBITMQ_DEFAULT_USER}}:${{RABBITMQ_DEFAULT_PASS}}@${{RAILWAY_TCP_PROXY_DOMAIN}}:${{RAILWAY_TCP_PROXY_PORT}}
Works
Brody
Brody•5mo ago
awsome
Muijf
Muijf•5mo ago
That's stupid though. To be stuck on this because of a username or password I've never seen that
Brody
Brody•5mo ago
it do be dumb
Muijf
Muijf•5mo ago
I used the same username and generated another secret using the railway utils from the cmd menu and it works So it is the same length as before And it works I swear I used the inline shared variable feature before this too. So I think it's railway's fault not parsing it correctly. Maybe something failed to save internally
Brody
Brody•5mo ago
you deployed the template and then changed the username and password variables right? yeah just tested, those two variables are single set only, so after you changed the username and password and used the new credentials in the connection url you where using the wrong credentials since the original username and passwords where still set
Muijf
Muijf•5mo ago
After retrying it doesn't work anymore. I've set the variables before deploying but when trying to connect it says 'PLAIN login refused: user 'app' - invalid credentials' So the variables weren't used for some reason I had it working, but I wanted to recreate it again because it's very inconsistent
Brody
Brody•5mo ago
i just tested with my own template and it works perfectly
Muijf
Muijf•5mo ago
When changing the password and prompting a redeploy it will have 0 build logs
Brody
Brody•5mo ago
you cant change the credentials without wiping the volume afterwards, those variables are single set only
Muijf
Muijf•5mo ago
Let me try that sorry didn't see you say that Alright thanks I didn't know single set variables were a thing That makes things moving forward so much easier I thought it would just rebuild. But apparently the passwords are stored in the volume?
Brody
Brody•5mo ago
yep thats how rabbitmq works iirc same with postgres
Muijf
Muijf•5mo ago
Quick question. Is there a way to depend on other services?
Brody
Brody•5mo ago
like deploy this service after this service becomes healthy type thing you can do in compose?
Muijf
Muijf•5mo ago
Yes
Brody
Brody•5mo ago
nope 😭
Muijf
Muijf•5mo ago
My postgres services are running fine but for some reason my prisma deploy gives me a " FATAL: the database system is starting up". It sometimes goes through, and sometimes it doesn't. Maybe for another thread
Brody
Brody•5mo ago
you can only do work arounds like wait-for-it.sh, nc, pg_isready, sleep 3 in the start command
chirag
chirag•5mo ago
the ui for dashboard makes you think you can create links between services lol
Brody
Brody•5mo ago
elaborate?
chirag
chirag•5mo ago
i spent minutes clicking on service and then trying to join it with other.
Brody
Brody•5mo ago
interesting
chirag
chirag•5mo ago
because the ui gives whiteboard like feel
Brody
Brody•5mo ago
nope, not possible beyond just grouping stuff, it has no effect on the order that stuff is deployed https://community.railway.app/discuss/thread/service-groups-c1faed81
chirag
chirag•5mo ago
yes I know but imagine being able to create a graph for your services
Brody
Brody•5mo ago
a graph?
chirag
chirag•5mo ago
something like this
No description
Brody
Brody•5mo ago
add that to https://community.railway.app/feedback but lets not hijack OP's thread any longer please
Muijf
Muijf•5mo ago
the framework railway is using has full support for those kind of things I am pretty sure not sure what it's called anymore full support as in frontend* react-flow it's called
Brody
Brody•5mo ago
that sounds familiar, dont know if they are still using it or have rolled their own solution @Melissa this is the thread, it's not super straightforward because it threw me for a loop before I came to the final conclusion here