Search code examples
javascriptrabbitmqweb-stomp

webstomp JS - getting a non-loopback access denied when trying to send rabbitmq message


I'm trying to send messages to rabbitmq with an HTML page with JS script which has the following lines:

var client = new StompJs.Client({
        brokerURL: 'ws://localhost:15674/ws',
        connectedHeaders: { login: 'my_rabbit_username', passcode: 'my_rabbit_password' },
        reconnectDelay: 5000,
        heartbeatIncoming: 4000,
        heartbeatOutgoing: 4000,
    });
client.activate();
function update_rabbit(){
        var rabbitName = document.getElementById("myRabbitLoc").value;
        console.log(rabbitName);
        client = new StompJs.Client({
            brokerURL: rabbitName,
            connectedHeaders: { login: 'my_rabbit_username', passcode: 'my_rabbit_password' },
            reconnectDelay: 5000,
            heartbeatIncoming: 4000,
            heartbeatOutgoing: 4000,
            });
        client.activate();
    }
 client.onStompError = function (frame) {
      // Will be invoked in case of error encountered at Broker
      // Bad login/passcode typically will cause an error
      // Complaint brokers will set `message` header with a brief message. Body may contain details.
      // Compliant brokers will terminate the connection after any error
      console.log('Broker reported error: ' + frame.headers['message']);
      console.log('Additional details: ' + frame.body);
    };

however if I'm trying to change "localhost" to any other pc name in my local network, or even change it to my own machine name the message won't arrive. and I'm getting the following message:

Broker reported error: Bad CONNECT
xxx.html:153 Additional details: non-loopback access denied

Would really appreciate any help on how to make this work

Edit: managed to avoid error report when changing to my computer name, but the messages still won't be delivered . when trying to change it to another network computer, getting the following errors:

WebSocket connection to 'ws://xxx.xxx.net/15674/ws' failed: 
_createWebSocket @ client.ts:510
(anonymous) @ client.ts:432
fulfilled @ byte.ts:13

which keep on going...


Solution

  • apparently my first connection code was somewhat wrong. I've use the phrase

    connectedHeaders: { login: 'my_rabbit_username', passcode: 'my_rabbit_password' },
    

    whereas I should have used:

    connectHeaders: { login: 'my_rabbit_username', passcode: 'my_rabbit_password' },
    

    (without 'ed' in the word connected) it's frustrating but that was it :D