This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: WouterLefever <wouter.lefever@hotmail.com>
- Loading branch information
1 parent
414c2ae
commit 389e368
Showing
18 changed files
with
152 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...informatievlaanderen/vsds/demonstrator/member/rest/websocket/MemberCounterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket; | ||
|
||
import be.informatievlaanderen.vsds.demonstrator.member.application.services.MemberService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class MemberCounterController { | ||
private final SimpMessagingTemplate template; | ||
private final MemberService memberService; | ||
|
||
@Autowired | ||
public MemberCounterController(SimpMessagingTemplate template, MemberService memberService) { | ||
this.template = template; | ||
this.memberService = memberService; | ||
} | ||
|
||
@Scheduled(fixedDelay = 60000) | ||
public void send() { | ||
long counter = memberService.getNumberOfMembers(); | ||
this.template.convertAndSend("/broker/membercounter", counter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
...java/be/informatievlaanderen/vsds/demonstrator/member/rest/websocket/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...rmatievlaanderen/vsds/demonstrator/member/rest/websocket/MemberCounterControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package be.informatievlaanderen.vsds.demonstrator.member.rest.websocket; | ||
|
||
import be.informatievlaanderen.vsds.demonstrator.member.application.services.MemberService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
|
||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MemberCounterControllerTest { | ||
|
||
@Mock | ||
private MemberService memberService; | ||
@Mock | ||
private SimpMessagingTemplate simpMessagingTemplate; | ||
@InjectMocks | ||
private MemberCounterController memberCounterController; | ||
|
||
@Test | ||
void test(){ | ||
when(memberService.getNumberOfMembers()).thenReturn(76L); | ||
memberCounterController.send(); | ||
|
||
verify(memberService).getNumberOfMembers(); | ||
verify(simpMessagingTemplate).convertAndSend("/broker/membercounter",76L); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<template> | ||
<h1 class="header5 centered">Aantal members: {{ memberCounter }}</h1> | ||
</template> | ||
|
||
<script> | ||
import "leaflet/dist/leaflet.css" | ||
import Stomp from "webstomp-client"; | ||
export default { | ||
name: "ConnectionState", | ||
data() { | ||
return { | ||
memberCounter: 0, | ||
stompClient: null | ||
}; | ||
}, | ||
mounted() { | ||
this.connect() | ||
}, | ||
methods: { | ||
//websocket | ||
connect() { | ||
this.stompClient = new Stomp.client('ws://localhost:8084/update', {debug: false}); | ||
this.stompClient.connect( | ||
{}, | ||
() => { | ||
this.stompClient.subscribe("/broker/membercounter", (memberCounter) => { | ||
this.memberCounter = JSON.parse(memberCounter.body) | ||
}); | ||
}, | ||
error => { | ||
console.log(error); | ||
this.connect() | ||
} | ||
); | ||
}, | ||
disconnect() { | ||
if (this.stompClient) { | ||
this.stompClient.disconnect(); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style> | ||
.centered { | ||
text-align: center | ||
} | ||
</style> |