0

I'm getting this cryptic "Response code 400 (Bad Request)" error message when I try to publish a message to rabbitmq. This is what my request looks like:

            got.post(`https://rabbit.somedomain.com/api/exchanges/%2F/${exchange}/publish`, {
                headers: {
                    Authorization: 'Basic ' + Buffer.from('myusername:password').toString('base64'),
                },
                json: {
                    properties: {},
                    routing_key,
                    payload: 'test',
                    payload_encoding: 'string'
                },
                timeout: 10000,
                responseType: 'json',
            }).then(response => {
                if (Number(response.statusCode) !== 200) {
                    throw new Error(response);
                }
                console.log('success');
            }).catch(err => {
                console.log('failed to publish message:', err);
            });

As you'd expect, this request works perfectly using Postman. I get the success response:

{
    "routed": true
}

More so, the problem appears specific to the /publish endpoint. For instance I don't get this error from the /bindings or /exchanges endpoints. Normally the error responses are in the form {"error":"bad_request","reason":"whatever_is_wrong"} so at least I'd be able to debug, but not the case here. This is the closest to this problem that I've found but the suggestions there don't solve my problem. I'm doing this in a nodejs server by the way. Pretty stumped here, I'd greatly appreciate any help. Thanks!

Uche Ozoemena
  • 816
  • 2
  • 10
  • 25
  • 1
    On a side node , consider using AMQP client it will be much faster and give you a higher through put – Soumen Mukherjee Nov 08 '20 at 14:01
  • Are you saying that the response body is empty, and the HTTP status code is 400; or that the response body is the actual string "Response code 400 (Bad Request)"? – IMSoP Nov 09 '20 at 08:31
  • @IMSoP I mean that the response comes back with a 400 status code, and the body contains the cryptic error message. – Uche Ozoemena Nov 09 '20 at 09:16

0 Answers0