What is this RunnableListener
interface?
What is triggering this task - is it scheduled regularly?
Once the client has subscribed to a given topic (here, /topic/greetings
), you can send messages to that topic whenever you want using a MessagingTemplate
. For example, you could schedule this task and let it send messages regularly on a given topic:
@Service
public class GreetingService {
private SimpMessagingTemplate template;
@Autowired
public GreetingService(SimpMessagingTemplate template) {
this.template = template;
}
@Scheduled(fixedDelay=10000)
public void greet() {
this.template.convertAndSend("/topic/greetings", "Hello");
}
}
Check out the reference documentation for more details.