public final class WebSocketMethods extends Object
A utility class for WebSocket-related operations, with one-liners that make it easy to send WebSocket messages.
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.
Constructor and Description |
---|
WebSocketMethods(SimpMessageSendingOperations messaging) |
Modifier and Type | Method and Description |
---|---|
static void |
sendWSMessage(String destination,
Message<?> message)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
Object message)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
Object payload,
Map<String,Object> headers)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
Object payload,
Map<String,Object> headers,
MessagePostProcessor postProcessor)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
Object payload,
MessagePostProcessor postProcessor)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
String user,
Object payload)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
String user,
Object payload,
Map<String,Object> headers)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
String user,
Object payload,
Map<String,Object> headers,
MessagePostProcessor postProcessor)
Send a WebSocket message.
|
static void |
sendWSMessage(String destination,
String user,
Object payload,
MessagePostProcessor postProcessor)
Send a WebSocket message.
|
@Autowired WebSocketMethods(SimpMessageSendingOperations messaging)
public static void sendWSMessage(String destination, Object message)
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' destination.sendWSMessage( 'Hello, world' )
destination
- where the message will be sentmessage
- message to be sentpublic static void sendWSMessage(String destination, Object payload, Map<String,Object> headers) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] destination.sendWSMessage( 'Hello, world' , headers )
destination
- where the message will be sentpayload
- message to be sentheaders
- headers to include in the requestMessagingException
public static void sendWSMessage(String destination, Message<?> message) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' Message message = new Message(); destination.sendWSMessage( message, headers )
destination
- where the message will be sentmessage
- message to be sentMessagingException
public static void sendWSMessage(String destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( payload, processor )
destination
- where the message will be sentpayload
- message to be sentpostProcessor
- processes a message after creation; returning the old, new, or modified messageMessagingException
public static void sendWSMessage(String destination, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( payload, headers, processor )
destination
- where the message will be sentpayload
- message to be sentheaders
- headers to include in the requestpostProcessor
- processes a message after creation; returning the old, new, or modified messageMessagingException
public static void sendWSMessage(String destination, String user, Object payload) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' destination.sendWSMessage( 'john', 'Hello, world' )
destination
- where the message will be sentpayload
- message to be sentuser
- the recipient of the messageMessagingException
public static void sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] destination.sendWSMessage( 'john', 'Hello, world', headers )
destination
- where the message will be sentpayload
- message to be sentuser
- the recipient of the messageMessagingException
public static void sendWSMessage(String destination, String user, Object payload, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' MessageProcessor processor = { message -> 'Hello, world' return message } destination.sendWSMessage( 'jane', payload , processor )
destination
- where the message will be sentuser
- the recipient of the messagepayload
- message to be sentpostProcessor
- processes a message after creation; returning the old, new, or modified messageMessagingException
public static void sendWSMessage(String destination, String user, Object payload, Map<String,Object> headers, MessagePostProcessor postProcessor) throws MessagingException
Send a WebSocket message.
Example usage:
String destination = '/topic/greetings' def headers = [ username : 'john', password : '1234abc' ] MessageProcessor processor = { message -> 'This is a sample message' return message } destination.sendWSMessage( 'john', payload , headers, processor )
destination
- where the message will be sentuser
- the recipient of the messagepayload
- message to be sentheaders
- headers to include in the requestpostProcessor
- processes a message after creation; returning the old, new, or modified messageMessagingException
Copyright © 2023. All rights reserved.