Explore Spring 4 Features: WebSocket (Part II)
Now for the phase II to be in action, a asynchronous task needs to be scheduled, which at regular intervals, with the help of a Scheduler would post messages to MessageBroker.When the client would connect to the MessageBroker over WebSocket, it would start receiving the messages. Now, here we cannot use Spring Scheduling features i.e. @EnableScheduling or @EnableAsync , as when we use @EnableWebSocketMessageBroker , then Spring automatically configures two schedulers by default,and Spring 4 does not allow more than two Schedulers at a time. To overcome this limitation, we are using an implementation of SchedulingConfigurer. In its implementation, we are injecting a service. We will be calling a method of the service at regular interval, which will send messages to the MessageBroker. The code for SchedulingConfigurer implementation is: @Configuration @EnableScheduling public class SpringWebSchedulingConfig implements SchedulingConfigurer { @Autowired IMessageServi