R
Railway•11mo ago
Muijf

how to I connect to a rabbitmq service internally?

I can't seem to connect.
90 Replies
Percy
Percy•11mo ago
Project ID: 691265c1-a324-4034-8288-642c7ab38ebc
Muijf
MuijfOP•11mo ago
691265c1-a324-4034-8288-642c7ab38ebc I am using amqp://<user>:<password>@rabbitmq.railway.internal:5672 from another service.
Brody
Brody•11mo ago
what specific error do you get?
Muijf
MuijfOP•11mo 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•11mo ago
send it anyway? lol
Muijf
MuijfOP•11mo ago
error

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

url: "amqp://<user>:<password>@rabbitmq.railway.internal:5672"
Brody
Brody•11mo ago
oh wow you weren't kidding when you said "just error"
Muijf
MuijfOP•11mo ago
yup
Brody
Brody•11mo ago
I assume you can connect just fine when on railway if you where to swap to the public url?
Muijf
MuijfOP•11mo ago
If I open a tcp proxy and use that? I can try
Brody
Brody•11mo ago
yes please do
Muijf
MuijfOP•11mo ago
Deploying right now, 1 sec No I can't use the public uri either apparently
Brody
Brody•11mo ago
same vague error?
Muijf
MuijfOP•11mo ago
Yes
Brody
Brody•11mo ago
now you say it works locally, that means you are running rabbitmq locally too?
Muijf
MuijfOP•11mo ago
Yes Using a dev container and docker compose with the same docker image for rabbitmq and environment variables too
Brody
Brody•11mo ago
same image running locally as you run on railway?
Muijf
MuijfOP•11mo ago
Yes
Brody
Brody•11mo ago
can you run your app locally but connect to the rabbitmq hosted on railway?
Muijf
MuijfOP•11mo ago
I'll get back to you on that in 15 mins, quick break
Brody
Brody•11mo ago
sounds good
Muijf
MuijfOP•11mo ago
Doesn't seem to work either.. I can't seem to figure out why
Brody
Brody•11mo ago
same error?
Muijf
MuijfOP•11mo ago
Yes Tried everything, not sure
Brody
Brody•11mo ago
can you send the logs from your rabbitmq service? https://bookmarklets.up.railway.app/log-downloader/
Brody
Brody•11mo ago
its in the active state right?
Muijf
MuijfOP•11mo ago
yes
Brody
Brody•11mo 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
MuijfOP•11mo ago
Repo > Dockerfile
Brody
Brody•11mo ago
yeah gotcha, not a direct image deploy
Muijf
MuijfOP•11mo ago
yes
Brody
Brody•11mo ago
are you using the rabbitmq template?
Muijf
MuijfOP•11mo ago
I do kinda, but only kept the base image. I removed the quickstart
Brody
Brody•11mo ago
show me how you run rabbitmq locally?
Muijf
MuijfOP•11mo 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•11mo ago
show me your in code client?
Muijf
MuijfOP•11mo 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•11mo 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•11mo ago
they cant even connect to the public url of rabbitmq locally
Muijf
MuijfOP•11mo 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•11mo ago
you can connect to rabbitmq thats hosted on railway from your locally running app?
Muijf
MuijfOP•11mo ago
I can't I can connect to my local rabbitmq using bun runtime
chirag
chirag•11mo 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•11mo ago
nope the public tcp proxy is ipv4
chirag
chirag•11mo ago
the internal one is ipv6
Brody
Brody•11mo ago
i am aware, but they cant use either
chirag
chirag•11mo 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•11mo ago
they cant connect to it locally, please read through this thread
Muijf
MuijfOP•11mo 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•11mo ago
update: i can
Brody
Brody•11mo ago
No description
No description
Muijf
MuijfOP•11mo ago
So it must be bun
Brody
Brody•11mo ago
thats what im thinking too but use this url amqp://brody:[email protected]:59808 to run a connect test locally
Muijf
MuijfOP•11mo ago
That works, using the same environment as before So I am doing something wrong then
Brody
Brody•11mo 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
MuijfOP•11mo ago
Sure let me try that. That's the only difference right now I think
Brody
Brody•11mo 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
MuijfOP•11mo ago
Nah it's okay I am doing that right now
Brody
Brody•11mo ago
i mean id still like to so i know its done correctly
Muijf
MuijfOP•11mo 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•11mo ago
awsome
Muijf
MuijfOP•11mo ago
That's stupid though. To be stuck on this because of a username or password I've never seen that
Brody
Brody•11mo ago
it do be dumb
Muijf
MuijfOP•11mo 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•11mo 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
MuijfOP•11mo 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•11mo ago
i just tested with my own template and it works perfectly
Muijf
MuijfOP•11mo ago
When changing the password and prompting a redeploy it will have 0 build logs
Brody
Brody•11mo ago
you cant change the credentials without wiping the volume afterwards, those variables are single set only
Muijf
MuijfOP•11mo 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•11mo ago
yep thats how rabbitmq works iirc same with postgres
Muijf
MuijfOP•11mo ago
Quick question. Is there a way to depend on other services?
Brody
Brody•11mo ago
like deploy this service after this service becomes healthy type thing you can do in compose?
Muijf
MuijfOP•11mo ago
Yes
Brody
Brody•11mo ago
nope 😭
Muijf
MuijfOP•11mo 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•11mo ago
you can only do work arounds like wait-for-it.sh, nc, pg_isready, sleep 3 in the start command
chirag
chirag•11mo ago
the ui for dashboard makes you think you can create links between services lol
Brody
Brody•11mo ago
elaborate?
chirag
chirag•11mo ago
i spent minutes clicking on service and then trying to join it with other.
Brody
Brody•11mo ago
interesting
chirag
chirag•11mo ago
because the ui gives whiteboard like feel
Brody
Brody•11mo 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•11mo ago
yes I know but imagine being able to create a graph for your services
Brody
Brody•11mo ago
a graph?
chirag
chirag•11mo ago
something like this
No description
Brody
Brody•11mo ago
add that to https://community.railway.app/feedback but lets not hijack OP's thread any longer please
Muijf
MuijfOP•11mo 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•11mo 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
Want results from more Discord servers?
Add your server