title: Websocket breaks when the page is reloaded
body: <p>We have a Java application that sends messages through a stomp connection over websocket using SpringBoot messaging support. The data should be sent to specific users once they connect and subscribe to the topic but when we reload the page the websocket breaks and never sends any messages again.</p>
  <p>We listen for the SessionSubscribeEvent here (so we can send an initial message after subscription is made):</p>
  <pre><code>@Component
  @AllArgsConstructor
  public class TransactionSubscriptionListener implements ApplicationListener&lt;SessionSubscribeEvent&gt; {
  
      private static final String DESTINATION_HEADER = &quot;simpDestination&quot;;
  
      private final RegionTransactionSender regionTransactionSender;
  
      @Override
      public void onApplicationEvent(SessionSubscribeEvent subscribeEvent) {
          Object simpDestination = subscribeEvent.getMessage().getHeaders().get(DESTINATION_HEADER);
          if (simpDestination == null) {
              return;
          }
  
          String destination = String.valueOf(simpDestination);
  
          if (destination.matches(RegionTransactionSender.REGEXP)) {
              regionTransactionSender.send();
          }
      }
  }
  </code></pre>
  <p>Region transaction sender implementation:</p>
  <pre><code>@Component
  @AllArgsConstructor
  public class RegionTransactionSender {
  
      public static final String REGEXP =
      ApiVersionConstants.TRANSACTIONS_FOR_REGION_DESTINATION_WITH_SUBSCRIBER + &quot;/\\S*&quot;;
  
      private static final String TOPIC_URL_PREFIX = ApiVersionConstants.TRANSACTIONS_FOR_REGION_DESTINATION + &quot;/&quot;;
  
      private final SimpMessageSendingOperations sendingOperations;
  
      private final TransactionService transactionService;
  
      private final SimpUserRegistry simpUserRegistry;
  
      public void send() {
          Set&lt;SimpUser&gt; users = simpUserRegistry.getUsers();
          users.stream()
              .filter(SimpUser::hasSessions)
              .forEach(this::sendToSubscriptions);
      }
  
      private void sendToSubscriptions(SimpUser user) {
          user.getSessions().forEach(session -&gt; session.getSubscriptions()
              .forEach(subscription -&gt; sendToTopics(user, subscription)));
      }
  
      private void sendToTopics(final SimpUser user, final SimpSubscription subscription) {
          String destination = subscription.getDestination();
  
          if (destination.matches(REGEXP)) {
              Optional&lt;String&gt; regionOptional = WebsocketUtils.retrieveOrganizationRegionFromDestination(destination);
              regionOptional.ifPresent(region -&gt; sendForRegionTopic(user, region));
          }
      }
  
      private void sendForRegionTopic(final SimpUser user, final String region) {
          Set&lt;TransactionResponse&gt; transactionsForRegion = transactionService
              .getTransactionsForRegion(AbstractWebsocketSender.TRANSACTIONS_COUNT, region);
  
          sendingOperations.convertAndSendToUser(user.getName(), TOPIC_URL_PREFIX + region, transactionsForRegion);
      }
  }
  </code></pre>
  <p>The <em>send()</em> method is called later on but no messages are sent.</p>
  <p><a href="https://i.stack.imgur.com/2fHG5.png" rel="nofollow noreferrer">Messages visible in Chrome's network debugging tool</a></p>
  <p>As you can see our other websocket (<em>systemBalanceSummary</em>) works great. The difference is that on <em>systemBalanceSummary</em> we sent messages to a non user-specific destination.
  It's also worth mentioning that when we access the website for the first time everything works fine.</p>
  <p>Why does that websocket break when we reload the page?</p>
  <p><strong>EDIT</strong></p>
  <p>After some debugging we've found out that even though the subscription event is fired there are no users in <em>SimpUserRegistry</em> but we do not know what causes that.</p>