Skip to content

Commit

Permalink
before adding auth & api gateway services
Browse files Browse the repository at this point in the history
  • Loading branch information
guxiong committed Aug 13, 2019
1 parent 49b5fad commit 7595dde
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
docker-mongodb/data/
docker-mongodb/data/*
*/target
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public Queue queue() {
@Bean
public Binding binding(Queue queue, Exchange dataExchange) {
return BindingBuilder
.bind(queue)
.to(dataExchange)
.with(Constants.ROUTING_KEY_HISTORY).noargs();
.bind(queue)
.to(dataExchange)
.with(Constants.ROUTING_KEY_HISTORY).noargs();
}

public static void main(String[] args) {
Expand Down
24 changes: 12 additions & 12 deletions data-dashboard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

<dependencies>
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-dependencies</artifactId>-->
<!--<version>2.0.1.RELEASE</version>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-dependencies</artifactId>-->
<!--<version>2.0.1.RELEASE</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -27,19 +27,19 @@
<artifactId>spring-rabbit</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>io.projectreactor</groupId>-->
<!--<artifactId>reactor-net</artifactId>-->
<!--<version>2.0.5.RELEASE</version>-->
<!--<groupId>io.projectreactor</groupId>-->
<!--<artifactId>reactor-net</artifactId>-->
<!--<version>2.0.5.RELEASE</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>io.projectreactor</groupId>-->
<!--<artifactId>reactor-core</artifactId>-->
<!--<version>2.0.5.RELEASE</version>-->
<!--<groupId>io.projectreactor</groupId>-->
<!--<artifactId>reactor-core</artifactId>-->
<!--<version>2.0.5.RELEASE</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>io.netty</groupId>-->
<!--<artifactId>netty-all</artifactId>-->
<!--<version>4.0.33.Final</version>-->
<!--<groupId>io.netty</groupId>-->
<!--<artifactId>netty-all</artifactId>-->
<!--<version>4.0.33.Final</version>-->
<!--</dependency>-->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Binding binding(Queue queue, Exchange dataExchange) {
.to(dataExchange)
.with(Constants.ROUTING_KEY_REALTIME).noargs();
}

public static void main(String[] args) {
SpringApplication.run(DataDashboardApplication.class, args);
}
Expand Down
83 changes: 42 additions & 41 deletions data-dashboard/src/main/resources/static/WebSocketController.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
class WebSocketController {
constructor() {
this._onConnected = this._onConnected.bind(this);
}
_onConnected(frame) {

constructor() {
this._onConnected = this._onConnected.bind(this);
}

_onConnected(frame) {
this.setConnected(true);
console.log('Connected: ' + frame);
this.stompClient.subscribe('/topic/realtime', this.showMessage);
}
setConnected(connected) {
document.getElementById('connect').disabled = connected;
document.getElementById('disconnect').disabled = !connected;
document.getElementById('realtime').style.visibility = connected ? 'visible' : 'hidden';
document.getElementById('response').innerHTML = '';
}
connect() {
var socket = new SockJS('/websocket-app');
this.stompClient = Stomp.over(socket);
this.stompClient.connect({}, this._onConnected);
}

disconnect() {
if(this.stompClient != null) {
this.stompClient.disconnect();
}
this.setConnected(false);
console.log("Disconnected");
}
sendMessage() {
var message = document.getElementById('text').value;
this.stompClient.send("/app/message", {}, message);
}
showMessage(message) {
var response = document.getElementById('response');
var p = document.createElement('p');
p.style.wordWrap = 'break-word';
p.appendChild(document.createTextNode(message.body));
response.appendChild(p);
}
}

setConnected(connected) {
document.getElementById('connect').disabled = connected;
document.getElementById('disconnect').disabled = !connected;
document.getElementById('realtime').style.visibility = connected ? 'visible' : 'hidden';
document.getElementById('response').innerHTML = '';
}

connect() {
var socket = new SockJS('/websocket-app');
this.stompClient = Stomp.over(socket);
this.stompClient.connect({}, this._onConnected);
}

disconnect() {
if (this.stompClient != null) {
this.stompClient.disconnect();
}
this.setConnected(false);
console.log("Disconnected");
}

sendMessage() {
var message = document.getElementById('text').value;
this.stompClient.send("/app/message", {}, message);
}

showMessage(message) {
var response = document.getElementById('response');
var p = document.createElement('p');
p.style.wordWrap = 'break-word';
p.appendChild(document.createTextNode(message.body));
response.appendChild(p);
}

}

var webSocket = new WebSocketController();
44 changes: 22 additions & 22 deletions data-dashboard/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<html>
<head>
<title>Spring WebSocket Messaging</title>
<script src="/webjars/sockjs-client/sockjs.min.js"></script>
<script src="/webjars/stomp-websocket/stomp.min.js"></script>
<script src="/WebSocketController.js"></script>
</head>
<body onload="webSocket.disconnect()">
<div>
<div>
<button id="connect" onclick="webSocket.connect();">Connect to Real Time Data</button>
<button id="disconnect" disabled="disabled" onclick="webSocket.disconnect();">
Clear the Dashboard
</button>
</div>
<br />
<div id="realtime">
<!--<input type="text" id="text" placeholder="Write a message..."/>-->
<!--<button id="sendMessage" onclick="webSocket.sendMessage();">Send</button>-->
<p id="response"></p>
</div>
</div>
</body>
<head>
<title>Spring WebSocket Messaging</title>
<script src="/webjars/sockjs-client/sockjs.min.js"></script>
<script src="/webjars/stomp-websocket/stomp.min.js"></script>
<script src="/WebSocketController.js"></script>
</head>
<body onload="webSocket.disconnect()">
<div>
<div>
<button id="connect" onclick="webSocket.connect();">Connect to Real Time Data</button>
<button id="disconnect" disabled="disabled" onclick="webSocket.disconnect();">
Clear the Dashboard
</button>
</div>
<br/>
<div id="realtime">
<!--<input type="text" id="text" placeholder="Write a message..."/>-->
<!--<button id="sendMessage" onclick="webSocket.sendMessage();">Send</button>-->
<p id="response"></p>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,18 @@
import java.util.Date;


@RestController
@RestController // == @Controller + @ResponseBody
public class DataIngestController {

private static final Logger logger = LoggerFactory.getLogger(DataIngestController.class);

// @Autowired
// private SimpMessagingTemplate messagingTemplate;


// @Autowired
// private RestTemplate restTemplate;

@Autowired
private RabbitTemplate rabbitTemplate;

@Autowired
private Exchange exchange;





@PostMapping("/healthdata/ingest") // validate payload from request body
public HealthMonitorData ingest(@Valid @RequestBody HealthMonitorRawData rawData) {
// preprocess
Expand All @@ -53,13 +43,11 @@ public HealthMonitorData ingest(@Valid @RequestBody HealthMonitorRawData rawData
}



private HealthMonitorData preprocess(HealthMonitorRawData rawData) {
HealthMonitorData healthData = new HealthMonitorData();

// add more info from system
healthData.setTimestamp(new Date());
// airData.setSensorId()...

// standardize data format
healthData.setBloodPressure(Math.round(rawData.getBloodPressure() * 100.0) / 100.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class HealthMonitorRawData implements Serializable {

@NotNull
@Min(1)
@Max(100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void main(String[] args) {
@Override
public void run() {

HealthMonitorRawData payload = new HealthMonitorRawData(genRandom(), genRandom(), (int)genRandom(), (int)genRandom());
HealthMonitorRawData payload = new HealthMonitorRawData(genRandom(), genRandom(), (int) genRandom(), (int) genRandom());

HttpEntity<HealthMonitorRawData> request = new HttpEntity<>(payload);

Expand Down
16 changes: 8 additions & 8 deletions docker-rabbitmq/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: '2'
services:
sonar:
container_name: aiwin-rabbit
image: aiwin/rabbitmq-stomp:latest
ports:
- 61613:61613
- 15674:15674
- 15672:15672
- 5672:5672
sonar:
container_name: aiwin-rabbit
image: aiwin/rabbitmq-stomp:latest
ports:
- 61613:61613
- 15674:15674
- 15672:15672
- 5672:5672
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,33 @@

<packaging>pom</packaging>

<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down

0 comments on commit 7595dde

Please sign in to comment.