14 Mart 2018 Çarşamba

SpringStomp StandardWebSocketClient Sınıfı - Stomp İçin Transport Olarak Kullanılır

Giriş
Bu sınıf WebSocketStompClient nesnesine parametre olarak geçilir.

constructor
Şöyle yaparız
WebSocketClient simpleWebSocketClient = new StandardWebSocketClient();
doHandshake metodu
Şöyle yaparız
final CountDownLatch latch = new CountDownLatch(1);
EchoHandler handler = new EchoHandler(latch);
WebSocketClient client = new StandardWebSocketClient();
WebSocketSession session = client.doHandshake(handler, ECHO_URL).get();
session.sendMessage(new TextMessage("Hello World"));
latch.await(5000, TimeUnit.SECONDS);
session.close();

public class EchoHandler extends TextWebSocketHandler {

  private final CountDownLatch latch;

  public EchoHandler(CountDownLatch latch) {
    this.latch = latch;
  }

  @Override
  public void handleTextMessage(WebSocketSession session, TextMessage message) {
    System.out.println("------- received client message ------");
    System.out.println(message.getPayload());
    System.out.println("--------- end client message ---------");
    latch.countDown();
  }
}

Hiç yorum yok:

Yorum Gönder