- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So... where's the punchline?
Admin
That actually made me chortle.
Admin
But what about that HTTP connection to RabbitMQ? How do you check if the HTTP connection to check the AMQP connection has succeeded?
Maybe you could open a SSH connection to grep the HTTP server logs and see if your request went through. Yeah, sounds good.
Admin
Doesn't even know about response.json...
Admin
This is a comment you'd normally expect from a devil's advocate, but nevertheless. There are good reasons to
Admin
What would happen here if NAT was involved?
Admin
I love how they construct the URL: variable hostname, magic-number port.
Admin
eth0, that is what if response and response.status_code == 200 is for. If the connection failed for any reason, either there won't be a response or there won't be a 200 response code. The code still trusts that the response is going to have json. If the response isn't json, then the code is going to throw an error in the line where they read it as json.
Admin
5672 is rabbitmq's "well known" port - it listens on port 5672 for amqp, port 15672 for HTTP API, 25672 for inter-node communication, so hardcoding that node isn't so crazy.
Admin
My comment comes at the ignorance of, before this article, having never heard of RabbitMQ. As I read through this, it seems the code is connecting to a RabbitMQ server and checking something else in that server to find if the connection was successful. That is, the code seems to assume the very subject of verification was already successful in trying to verify it was successful. Isn't it done at:
Admin
So many of this type of WTF, where a built-in method isn't used, can be explained by the so-called workaround being written before the built-in method was available. Whether it works or not is one thing, to to chide someone for not using something without showing it was actually available is weak.
Admin
It reminds me about class discussion during my degree about knowing whether one's connection is still up. So you come up with something and then call it. You get a return value indicating the connection is up. Fine. Now, one second later, what do you do? Are you going to trust that one-second-old return value? The connection could have dropped out right after your function returned.
Admin
RabbitMQ would've worked, but it was eaten by a Python. Truly Kafkaesque
Admin
It's interesting to note that RabbitMQ in particular is a fickle beast when it comes to connection status. For instance: when a connection enters blocked state (due to resource limits), it will happily accept packets... And route them to /dev/null. There's hardly any direct feedback, and the client is often unable to react (synchronously, at least), leaving broken pipes (and, in synchronous environments also hung processes) everywhere when the broker is restarted.
At our company we ultimately "solved" the problem by having a monitoring publisher/consumer pair, which feeds back to the services and tells them to maybe stop using the broker for a bit (an excellent waste of power, designed for lack of proper monitoring software).
Admin
Wait... the program opens up a connection to the username?
Admin
That's the first thing I thought too; and on the password port(?)
Admin
username:password@host
Admin
In the long run it's almost always easier, simpler and more maintainable NOT to use a complex third party tool to solve routine, well understood problems.
In the short run it pushes the product out on time, though...