Вопрос

I've just started to study Spring 4 stomp over websocket. What are the differences between these two? What cases should I use one over the another?

Это было полезно?

Решение

There is no difference: MessageSendingOperations is an interface - contract. SimpMessagingTemplate is a concrete implementation of the first one.

Typically it's enough to configure bean for concrete implementation, but inject it by type of its conctract:

@Bean
public MessageSendingOperations messagingTemplate() {
    return new SimpMessagingTemplate(this.inputChannel);
}

...

@Component
public class MyService {

   @Autowired
   private MessageSendingOperations  messagingTemplate;
}

Другие советы

While it is true that SimpMessagingTemplate class implements the contracts specified in the MessageSendingOperations interface, you will in practice use SimpMessagingTemplate when you want to send a message to a specific user.

This is because (at the time of writing), the SimpMessageTemplate also implements the subinterface SimpMessageSendingOperations that offers the convertAndSendToUser body of methods.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top