Skip to content

Commit 331cd2b

Browse files
committed
add example projects for websocket with gateway and activemq as shared broker
1 parent 8ec933c commit 331cd2b

File tree

38 files changed

+2683
-1
lines changed

38 files changed

+2683
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/target/
2-
!.mvn/wrapper/maven-wrapper.jar
2+
.mvn/wrapper/maven-wrapper.jar
3+
*/target/
4+
*/.mvn/wrapper/maven-wrapper.jar
35

46
### STS ###
57
.apt_generated

example.html

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css"/>
7+
<style>
8+
body {
9+
background-color: #f5f5f5;
10+
}
11+
12+
#main-content {
13+
max-width: 940px;
14+
padding: 2em 3em;
15+
margin: 0 auto 20px;
16+
background-color: #fff;
17+
border: 1px solid #e5e5e5;
18+
-webkit-border-radius: 5px;
19+
-moz-border-radius: 5px;
20+
border-radius: 5px;
21+
}
22+
</style>
23+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.3.0/sockjs.js"></script>
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js"></script>
26+
<script>
27+
var stompClient = null;
28+
29+
function setConnected(connected) {
30+
$("#connect").prop("disabled", connected);
31+
$("#disconnect").prop("disabled", !connected);
32+
if (connected) {
33+
$("#responses").show();
34+
} else {
35+
$("#responses").hide();
36+
}
37+
$("#messages").html("");
38+
}
39+
40+
function frameHandler(frame) {
41+
setConnected(true);
42+
console.log('Connected: ' + frame);
43+
stompClient.subscribe('/topic/outgoing', function (message) {
44+
showMessage(message.body);
45+
});
46+
}
47+
48+
function onSocketClose() {
49+
if (stompClient !== null) {
50+
stompClient.disconnect();
51+
}
52+
setConnected(false);
53+
console.log("Socket was closed. Setting connected to false!")
54+
}
55+
56+
function connect() {
57+
var socket = new SockJS('http://localhost:8080/websocket');
58+
stompClient = Stomp.over(socket);
59+
stompClient.connect({}, function(frame) { frameHandler(frame) });
60+
socket.onclose = function() { onSocketClose(); }
61+
}
62+
63+
function disconnect() {
64+
if (stompClient !== null) {
65+
stompClient.disconnect();
66+
}
67+
setConnected(false);
68+
console.log("Disconnected");
69+
}
70+
71+
function sendMessage() {
72+
stompClient.send("/app/incoming", {}, JSON.stringify({'message': $("#message").val()}));
73+
}
74+
75+
function showMessage(message) {
76+
$("#responses").prepend("<tr><td>" + new Date() + " - " + message + "</td></tr>");
77+
}
78+
79+
function reqListener() {
80+
console.log(this.responseText);
81+
}
82+
83+
$(function () {
84+
$("form").on('submit', function (e) {
85+
e.preventDefault();
86+
});
87+
$("#connect").click(function () {
88+
connect();
89+
});
90+
$("#disconnect").click(function () {
91+
disconnect();
92+
});
93+
$("#send").click(function () {
94+
sendMessage();
95+
});
96+
disconnect();
97+
});
98+
</script>
99+
</head>
100+
<body>
101+
<noscript><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websocket relies on Javascript being
102+
enabled. Please enable
103+
Javascript and reload this page!</h2></noscript>
104+
<div id="main-content" class="container">
105+
<div class="row">
106+
<div class="col-md-6">
107+
<form class="form-inline">
108+
<div class="form-group">
109+
<label for="connect">WebSocket connection:</label>
110+
<button id="connect" class="btn btn-default" type="submit">Connect</button>
111+
<button id="disconnect" class="btn btn-default" type="submit" disabled="disabled">Disconnect
112+
</button>
113+
</div>
114+
</form>
115+
</div>
116+
<div class="col-md-6">
117+
<form class="form-inline">
118+
<div class="form-group">
119+
<label for="message">Message:</label>
120+
<input type="text" id="message" class="form-control" placeholder="Your message here...">
121+
</div>
122+
<button id="send" class="btn btn-default" type="submit">Send</button>
123+
</form>
124+
</div>
125+
</div>
126+
<div class="row">
127+
<div class="col-md-12">
128+
<table id="responses" class="table table-striped">
129+
<thead>
130+
<tr>
131+
<th>Messages</th>
132+
</tr>
133+
</thead>
134+
<tbody id="messages">
135+
</tbody>
136+
</table>
137+
</div>
138+
</div>
139+
</div>
140+
</body>
141+
</html>

rabbit-docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: '3'
2+
3+
services:
4+
rabbitmq:
5+
build: ./rabbitmq_stomp
6+
labels:
7+
kompose.service.type: nodeport
8+
ports:
9+
- '4369:4369'
10+
- '5672:5672'
11+
- '25672:25672'
12+
- '15672:15672'
13+
- '61613:61613'
14+
volumes:
15+
- 'rabbitmq_data:/bitnami'
16+
volumes:
17+
rabbitmq_data:
18+
driver: local

rabbitmq_stomp/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM rabbitmq:3.7-management
2+
RUN rabbitmq-plugins enable --offline rabbitmq_mqtt rabbitmq_federation_management rabbitmq_stomp
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip

0 commit comments

Comments
 (0)