title: Client not receiving new message sent from Controller after save
body: <p>I have a project generated with jhipster 3.12.2 and I'm trying to send an Alarm message through websockets from my controller after I have saved it to the db. 
  The RestController can be called from the jhipster frontend (create new entity) or from a mobile application which send HTTP POST.</p>
  
  <p>For some reason my client (mobile application generated with ionic and angular) isn't receiving any new messages. What's wrong with my code?</p>
  
  <pre><code>@RestController
  @RequestMapping("/api")
  public class AlarmResource {
  
  private final Logger log = LoggerFactory.getLogger(AlarmResource.class);
  
  @Inject
  private AlarmService alarmService;
  
  @Inject
  SimpMessageSendingOperations messagingTemplate;
  
  @PostMapping(value = "/alarms")
  @Timed
  @CrossOrigin
  @Secured({AuthoritiesConstants.ALARM, AuthoritiesConstants.ADMIN, AuthoritiesConstants.EDITOR})
  public ResponseEntity&lt;Alarm&gt; createAlarm(@RequestBody Alarm alarm) throws URISyntaxException {
      log.debug("REST request to save Alarm : {}", alarm);
      if (alarm.getId() != null) {
          return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("alarm", "idexists", "A new alarm cannot already have an ID")).body(null);
      }
      if(alarm.getTimestamp_ms() == null) {
          BigDecimal now = new BigDecimal(System.currentTimeMillis());
          alarm.setTimestamp_ms(now);
      }
      Alarm result = alarmService.save(alarm);
  
      System.out.println("Sending ne alarm message");
      String dest = "/topic/alarmactivity";
      messagingTemplate.convertAndSend(dest, result);
  
  
      return ResponseEntity.created(new URI("/api/alarms/" + result.getId()))
          .headers(HeaderUtil.createEntityCreationAlert("alarm", result.getId().toString()))
          .body(result);
  }
  </code></pre>
  
  <p>AlarmMessageService:</p>
  
  <pre><code>@Controller
  public class AlarmMessageService  {
  
  private static final Logger log = LoggerFactory.getLogger(AlarmMessageService.class);
  
  
  private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  
  @SubscribeMapping("/topic/alarmactivity")
  @SendTo("/topic/alarmtracker")
  public Alarm sendAlarm(@Payload Alarm newAlarm, StompHeaderAccessor stompHeaderAccessor, Principal principal) {
      log.debug("Sending user tracking data {}", newAlarm);
      return newAlarm;
  }
  }
  </code></pre>
  
  <p>And tracker-service.js in client-side:</p>
  
  <pre><code>(function() {
  'use strict';
  /* globals SockJS, Stomp */
  
  angular
      .module('exampleApp')
      .factory('ExAlarmTrackerService', ExAlarmTrackerService);
  
  ExAlarmTrackerService.$inject = ['$rootScope', '$window', '$localStorage', '$http', 'API_URL','$q', 'AuthServerProvider', '$stomp'];
  
  function ExAlarmTrackerService ($rootScope, $window, $localStorage, $http, API_URL, $q, AuthServerProvider, $stomp) {
  
      var stompClient = null;
      var subscriber = null;
      var listener = $q.defer();
      var connected = $q.defer();
      var alreadyConnectedOnce = false;
  
      var service = {
          connect: connect,
          disconnect: disconnect,
          receive: receive,
          sendActivity: sendActivity,
          subscribe: subscribe,
          unsubscribe: unsubscribe
      };
  
      return service;
  
      function connect () {
          //building absolute path so that websocket doesnt fail when deploying with a context path
          var loc = $window.location;
          var url = API_URL + 'websocket/tracker';
          var authToken = AuthServerProvider.getToken();
          if(authToken){
              url += '?access_token=' + authToken;
          }
          var socket = new SockJS(url);
          stompClient = Stomp.over(socket);
          var stateChangeStart;
          var headers = {};
          stompClient.connect(headers, function() {
              connected.resolve('success');
              //sendActivity();
              if (!alreadyConnectedOnce) {
                  stateChangeStart = $rootScope.$on('$stateChangeStart', function () {
                      //sendActivity();
                      console.log("statechange");
                  });
                  alreadyConnectedOnce = true;
              }
          });
          $rootScope.$on('$destroy', function () {
              if(angular.isDefined(stateChangeStart) &amp;&amp; stateChangeStart !== null){
                  stateChangeStart();
              }
          });
      }
  
      function disconnect () {
          if (stompClient !== null) {
              stompClient.disconnect();
              stompClient = null;
          }
      }
  
      function receive () {
          return listener.promise;
      }
  
      function sendActivity() {
          if (stompClient !== null &amp;&amp; stompClient.connected) {
              stompClient
                  .send('/topic/activity',
                  {},
                  angular.toJson({'page': $rootScope.toState.name}));
          }
      }
  
      function subscribe () {
          connected.promise.then(function() {
              subscriber = stompClient.subscribe('/topic/alarmtracker', function(data) {
                  listener.notify(angular.fromJson(data.body));
              });
          }, null, null);
      }
  
      function unsubscribe () {
          if (subscriber !== null) {
              subscriber.unsubscribe();
          }
          listener = $q.defer();
      }
  
  
  }
  })();
  </code></pre>
  
  <p>And in my controller.js:</p>
  
  <pre><code> ExAlarmTrackerService.receive().then(null, null, function(activity) {
      console.log(activity);
   });
  </code></pre>