Does Rabbitmq-web-stomp support cross-domain access?

317 views
Skip to first unread message

Xuehan Xu

unread,
Jul 19, 2014, 5:36:58 AM7/19/14
to rabbitm...@googlegroups.com
Hi, everyone

I'm trying to connect to rabbitmq through the web. I have to machines, one is used as rabbitmq server with rabbitmq-web-stomp plugin enabled, while the other is used as client.

Here is my test html code that used to send messages to rabbitmq: 
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Stomp Websocet Exercise </title>
<script language="javascript" type="text/javascript">

var output;
var subscription;
var i=0;
var client;

var on_connect = function() {
writeToScreen('Connected');
}

var on_error = function(error) {
writeToScreen('Error: ' + error.headers.message);
}

var on_disconnect = function(){
writeToScreen('Disconnected');
}

function sendMsg(){
client.send("/topic/test", {priority: 9}, document.getElementById("msg").value);
}

function init() {
output = document.getElementById("output");

writeToScreen('Initializing...');
var ws = new SockJS('http://192.168.1.137:15674/stomp');
client = Stomp.over(ws);

client.heartbeat.outgoing=0;
client.heartbeat.incoming=0;
writeToScreen('Connecting...');
client.connect('xxh', 'xxh', on_connect, on_error, '/xxh');



}

function writeToScreen(message) { 
var pre = document.createElement("p");
pre.style.wordWrap = "break-word"; 
pre.innerHTML = message; 
output.appendChild(pre); 
}

window.addEventListener("load", init, false);

</script>
<h2>Stomp Websocket Test</h2>
<form action="#" onSubmit="sendMsg(); return false;">
         <input type="text" name="msg" id="msg" style="width: 300px" />
       </form>
<div id="output"></div>

The problem is this: 
    when I open this html file on the server machine, it can successfully connect to rabbitmq and send messages, however, when it is opened on the client machine, it seems that it's stuck when connecting rabbitmq server, as neither on_connect function nor on_error function is invoked.

Why is this happening? Is this due to some cross-domain access restriction? Please help me, Thank you:-)

Michael Klishin

unread,
Jul 19, 2014, 7:23:54 AM7/19/14
to rabbitm...@googlegroups.com, Xuehan Xu
 On 19 July 2014 at 13:37:00, Xuehan Xu (xxhdx1...@gmail.com) wrote:
> > The problem is this:
> when I open this html file on the server machine, it can successfully
> connect to rabbitmq and send messages, however, when it is opened
> on the client machine, it seems that it's stuck when connecting
> rabbitmq server, as neither on_connect function nor on_error
> function is invoked.

What's in RabbitMQ log? are you connecting with guest/guest?
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Xuehan Xu

unread,
Jul 19, 2014, 11:40:53 AM7/19/14
to rabbitm...@googlegroups.com, xxhdx1...@gmail.com
Hi, Thanks for the reply.

I created a user "xxh" and a virtual host "/xxh", and "xxh" has the access to "/xxh".

Xuehan Xu

unread,
Jul 19, 2014, 11:55:02 AM7/19/14
to rabbitm...@googlegroups.com, xxhdx1...@gmail.com
There's nothing in the log file

Michael Klishin

unread,
Jul 19, 2014, 11:57:07 AM7/19/14
to rabbitm...@googlegroups.com, Xuehan Xu
On 19 July 2014 at 19:55:05, Xuehan Xu (xxhdx1...@gmail.com) wrote:
> > There's nothing in the log file

Any errors in the browser console?

So far I cannot reproduce with a nearly identical setup. 

Xuehan Xu

unread,
Jul 19, 2014, 10:22:13 PM7/19/14
to rabbitm...@googlegroups.com, xxhdx1...@gmail.com
Hi, sorry, it was due to my windows firewall.

I turn the firewall down, and the problem is gone. Thank you for your help:-).  So sorry for the mistake.

Xuehan Xu

unread,
Jul 19, 2014, 10:57:02 PM7/19/14
to rabbitm...@googlegroups.com, xxhdx1...@gmail.com
Hi, sorry for interrupting you again.

Although with the windows firewall down, rabbitmq can be connected remotely, when I connect rabbitmq server with IE9.0, it still failed.

Should I do some more configuration? SOCKJS says it is available even when the browser doesn't support websocket.

Xuehan Xu

unread,
Jul 19, 2014, 10:58:33 PM7/19/14
to rabbitm...@googlegroups.com, xxhdx1...@gmail.com
By the way, the on_error function is also not invoked

Michael Klishin

unread,
Jul 20, 2014, 9:24:08 AM7/20/14
to rabbitm...@googlegroups.com, Xuehan Xu
On 20 July 2014 at 06:57:04, Xuehan Xu (xxhdx1...@gmail.com) wrote:
> > Although with the windows firewall down, rabbitmq can be connected
> remotely, when I connect rabbitmq server with IE9.0, it still
> failed.
>
> Should I do some more configuration? SOCKJS says it is available
> even when the browser doesn't support websocket.

Please post the exception stack trace (ideally using gist.github.com). It can be a SockJS
IE 9 compatibility issue. 

Anshuman Banerjee

unread,
Aug 27, 2014, 3:20:07 AM8/27/14
to rabbitm...@googlegroups.com
I have gone through a similar condition. I just enabled the universal access
of stomp port no.15674 on my Linux server that was running
Rabbitmq-server(from Linux server admin console), and configured it to be
freely accessed from remote machines. It solved the cross domain access
error for me. Hope it helps someone.

Reply all
Reply to author
Forward
0 new messages