Annotation Interface WebSocket


@Target(METHOD) @Retention(RUNTIME) @Documented public @interface WebSocket
Annotation to mark an endpoint method as handling HTTP WebSocket upgrade requests.

WebSockets allow bidirectional streaming text or binary communication with a client. Http method will always be GET.

Path Configuration: The annotation value specifies the path pattern for this endpoint, which is combined with the HttpEndpoint class-level path prefix to form the complete URL.

Request Bodies: WebSocket annotated methods must not accept a body parameter, there is no request body, instead additional data will have to be passed over the WebSocket connection after the upgrade completes.

Path Parameters: Use {paramName} in the path to identify the specific resource to create or update. These can be combined with request body parameters.

Return value: WebSocket annotated types must return Flow handling the stream of incoming messages, messages coming out of hte flow are emitted to the client. The incoming and outgoing message type must both be the same type. Supported types are String for text, ByteString for binary messages, or Message for a lower level handling of the protocol.

Example:


 @WebSocket("/ping-pong-websocket")
 public Flow<String, String, NotUsed> pingPong() {
     return Flow.of(String.class).map(incoming -> "pong: " + incoming)
 }
 

IMPORTANT WebSocket endpoints always work locally, but in a deployed service, require additional setup. See the Akka SDK documentation for more details about setup.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
     
  • Element Details

    • value

      String value
      Default:
      ""