Server load with Grails?
I want to create a connection between a client and a server with Grails so that the server sends messages to the client.
I tried events-push-plugin but I was unable to solve my problem using it.
+3
source to share
3 answers
Use http://grails.org/plugin/spring-websocket plugin (must use rake 2.4.4 and above)
In your service class, insert the service brokerMessagingTemplate and in your service method, press msg to the client
brokerMessagingTemplate.convertAndSend "/topic/hello", "hello from service!"
In the gsp file you need to subscribe to topic '/ topic / hello', below is some sample code.
<asset:javascript src="spring-websocket" />
<script type="text/javascript">
$(function() {
var socket = new SockJS("${createLink(uri: '/stomp')}");
var client = Stomp.over(socket);
client.connect({}, function() {
client.subscribe("/topic/hello", function(message) {
$("#helloDiv").append(message.body);
});
});
});
</script>
+3
source to share