Skip to content

Commit

Permalink
add consumer argument to websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdgeisler committed Nov 24, 2022
1 parent 8111418 commit f22490a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.function.Consumer;

@Component
public class ClientApi extends AbstractClientApi {
Expand Down Expand Up @@ -88,7 +89,7 @@ public Mono<Map> dump() {
.bodyToMono(Map.class);
}

public void websocket() {
public void websocket(final Consumer<String> consumer) {
final String token;
final String authorizationHeader;
final HttpClient httpClient;
Expand All @@ -103,10 +104,10 @@ public void websocket() {
.headers(headers -> headers.add(HttpHeaders.AUTHORIZATION, authorizationHeader))
.keepAlive(true);
client = new ReactorNettyWebSocketClient(httpClient);
client.execute(URI.create(String.format("https://%s:%d/v1/", hostname, port)), session ->
client.execute(URI.create(String.format("https://%s:%d/v1/", this.hostname, this.port)), session ->
session.receive()
.map(WebSocketMessage::getPayloadAsText)
.doOnNext(message -> log.debug("Received websocket message: {}", message))
.doOnNext(consumer)
.repeat()
.then()
).block();
Expand Down

0 comments on commit f22490a

Please sign in to comment.