es.prodevelop.pui9.websocket.PuiWebSocket Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es.prodevelop.pui9.services Show documentation
Show all versions of es.prodevelop.pui9.services Show documentation
Support for business layer (BO)
package es.prodevelop.pui9.websocket;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;
/**
* This class allows to send messages over WebSockets to the clients. It
*
* @author Marc Gil - [email protected]
*/
@Component
public class PuiWebSocket {
public static final String TOPIC_DESTINATION = "/topic/";
@Autowired
private SimpMessagingTemplate template;
private PuiWebSocket() {
}
/**
* Send a message to given destination with the indicated payload
*
* @param destination The destination of the message (/topic/sample)
* @param payload The object to be sent
*/
public void sendMessage(String destination, Object payload) {
this.sendMessage(destination, payload, null);
}
/**
* Send a message to given destination with the indicated payload. Additionally
* you can add some headers
*
* @param destination The destination of the message (/topic/sample)
* @param payload The object to be sent
* @param headers Additional headers to sent
*/
public void sendMessage(String destination, Object payload, Map headers) {
if (payload == null) {
payload = "";
}
template.convertAndSend(destination, payload, headers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy