forked from rabbitmq/rabbitmq-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
temp-queue.html
98 lines (85 loc) · 3.14 KB
/
temp-queue.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html><head>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="stomp.js"></script>
<style>
.box {
width: 440px;
float: left;
margin: 0 20px 0 20px;
}
.box div, .box input {
border: 1px solid;
-moz-border-radius: 4px;
border-radius: 4px;
width: 100%;
padding: 5px;
margin: 3px 0 10px 0;
}
.box div {
border-color: grey;
height: 300px;
overflow: auto;
}
div code {
display: block;
}
#first div code {
-moz-border-radius: 2px;
border-radius: 2px;
border: 1px solid #eee;
margin-bottom: 5px;
}
#second div {
font-size: 0.8em;
}
</style>
<title>RabbitMQ Web STOMP Examples : Temporary Queue</title>
<link href="main.css" rel="stylesheet" type="text/css"/>
</head><body lang="en">
<h1><a href="index.html">RabbitMQ Web STOMP Examples</a> > Temporary Queue</h1>
<p>When you type text in the form's input, the application will send a message to the <code>/queue/test</code> destination
with the <code>reply-to</code> header set to <code>/temp-queue/foo</code>.</p>
<p>The STOMP client sets a default <code>onreceive</code> callback to receive messages from this temporary queue and display the message's text.</p>
<p>Finally, the client subscribes to the <code>/queue/test</code> destination. When it receives message from this destination, it reverses the message's
text and reply by sending the reversed text to the destination defined by the message's <code>reply-to</code> header.</p>
<div id="first" class="box">
<h2>Received</h2>
<div></div>
<form><input autocomplete="off" placeholder="Type here..."></input></form>
</div>
<div id="second" class="box">
<h2>Logs</h2>
<div></div>
</div>
<script>
var ws = new WebSocket('ws://' + window.location.hostname + ':15674/ws');
var client = Stomp.over(ws);
client.debug = function(e) {
$('#second div').append($("<code>").text(e));
};
// default receive callback to get message from temporary queues
client.onreceive = function(m) {
$('#first div').append($("<code>").text(m.body));
}
var on_connect = function(x) {
id = client.subscribe("/queue/test", function(m) {
// reply by sending the reversed text to the temp queue defined in the "reply-to" header
var reversedText = m.body.split("").reverse().join("");
client.send(m.headers['reply-to'], {"content-type":"text/plain"}, reversedText);
});
};
var on_error = function() {
console.log('error');
};
client.connect('guest', 'guest', on_connect, on_error, '/');
$('#first form').submit(function() {
var text = $('#first form input').val();
if (text) {
client.send('/queue/test', {'reply-to': '/temp-queue/foo'}, text);
$('#first form input').val("");
}
return false;
});
</script>
</body></html>