[Beniner] Can not connect to stomp

762 views
Skip to first unread message

Pierre Amey

unread,
Jan 12, 2017, 4:51:25 PM1/12/17
to rabbitmq-users
Good evening all,

Today, I started with Rabbit and I can send MQTT message to my RabbitMQ server from MQTT.fs and from my Adafruit devise. That great!!

Now I m trying to display the message to a web page.

For this, I did the following
I enabled
sudo rabbitmq-plugins enable rabbitmq_web_stomp
sudo rabbitmq-plugins enable rabbitmq_web_stomp_examples

I created a index.php page in my apache server.
I imported to /var/www/rabbit/js/ the following


and I included it to my we page
<script src="js/sockjs-0.3.4.js"></script>
<!-- https://github.com/jmesnil/stomp-websocket/blob/master/lib/stomp.js -->
<script src="js/stomp.js"></script>

I also add another script
<script src="js/listener-app.js"></script>
and here is the code
// Use SockJS
Stomp.WebSocketClass = SockJS;

// Connection parameters
var mq_username = "fona",
 mq_password
= "fona",
 mq_vhost
= "/",
// mq_url = 'http://' + window.location.hostname + ':15674/stomp',
 mq_url
= 'http://127.0.0.1:15674/stomp',
 
// The queue we will read. The /topic/ queues are temporary
 
// queues that will be created when the client connects, and
 
// removed when the client disconnects. They will receive
 
// all messages published in the "amq.topic" exchange, with the
 
// given routing key, in this case "mymessages"
 
// mq_queue = "/topic/fona";
 mq_queue
="fona808";

// This is where we print incomoing messages
var output;

// This will be called upon successful connection
function on_connect() {
 output
.innerHTML += 'Connected to RabbitMQ-Web-Stomp<br />';
 console
.log(client);
 client
.subscribe(mq_queue, on_message);
}

// This will be called upon a connection error
function on_connect_error() {
 output
.innerHTML += 'Connection failed!<br />';
}

// This will be called upon arrival of a message
function on_message(m) {
 console
.log('message received');
 console
.log(m);
 output
.innerHTML += m.body + '<br />';
}

// Create a client
var client = Stomp.client(mq_url);

window
.onload = function () {
 
// Fetch output panel
 output
= document.getElementById("output");

 
// Connect
 client
.connect(
 mq_username
,
 mq_password
,
 on_connect
,
 on_connect_error
,
 mq_vhost
 
);
}


When I refresh my web page, I alway get the error
Connection failed!
and in the console I can see.
Opening Web Socket...
stomp
.js (line 145)


GET http
://127.0.0.1:15674/stomp/info
 
 
4ms
sockjs
-0.3.4.js (line 807)

Whoops! Lost connection to undefined

Now, I wundering a couple of thing.
Does my imported js files (stomps.js and sockjs-0.3.4.js) are correct source?
If not, were can I get the correct js script

I wundering why I have info (GET http://127.0.0.1:15674/stomp/info )

my mq_user and mq_password are correct. I have a doubt regarding mq_queue. While I am sending message, I do not need to write /topic/fona808, but I simply enter 'fona808' and the message are received in 'fona808' queue.
So, I guess my problem whould targeted on the the two imported js file, or may be I missed to setup something.

There si additionall task regarding stomp?

Thank for any help and advise!!
Cheers
Pierre


Reply all
Reply to author
Forward
0 new messages