本文整理了Java中io.advantageous.qbit.http.websocket.WebSocket.setTextMessageConsumer()
方法的一些代码示例,展示了WebSocket.setTextMessageConsumer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocket.setTextMessageConsumer()
方法的具体详情如下:
包路径:io.advantageous.qbit.http.websocket.WebSocket
类名称:WebSocket
方法名:setTextMessageConsumer
暂无
代码示例来源:origin: advantageous/qbit
private void wireWebSocket(final String serviceName, final String message) {
this.webSocket.setErrorConsumer(error -> {
if (error instanceof ConnectException) {
connected.set(false);
}
logger.error(sputs(this.getClass().getName(),
"::Exception calling WebSocket from client proxy",
"\nService Name", serviceName, "\nMessage", message), error);
});
//noinspection Convert2MethodRef
this.webSocket.setTextMessageConsumer(messageFromServer -> handleWebSocketReplyMessage(messageFromServer));
}
代码示例来源:origin: advantageous/qbit
public WebSocketTextQueue(final WebSocket webSocket, final int batchSize, final int flushInterval, final TimeUnit timeUnit) {
this.webSocket = webSocket;
this.stringQueue = QueueBuilder.queueBuilder().setBatchSize(batchSize).setPollWait(1000).build();
final SendQueue<String> sendQueue = this.stringQueue.sendQueueWithAutoFlush(flushInterval, timeUnit);
this.webSocket.setTextMessageConsumer(sendQueue::send);
}
代码示例来源:origin: advantageous/qbit
public WebSocketTextQueue(final WebSocket webSocket) {
this.webSocket = webSocket;
this.stringQueue = QueueBuilder.queueBuilder().setBatchSize(1).setLimit(100).setPollWait(1000).build();
final SendQueue<String> sendQueue = this.stringQueue.sendQueue();
this.webSocket.setTextMessageConsumer(sendQueue::send);
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNewOpenWaitWebSocketNewServerStuff() {
connect();
server.setWebSocketOnOpenConsumer(webSocket -> webSocket.setTextMessageConsumer(message -> {
if (message.equals("What do you want on your cheeseburger?")) {
webSocket.sendText("Bacon");
requestReceived.set(true);
} else {
puts("Websocket message", message);
}
}));
run();
final WebSocket webSocket = client.createWebSocket("/services/cheeseburger");
webSocket.setTextMessageConsumer(message -> {
if (message.equals("Bacon")) {
responseReceived.set(true);
}
});
webSocket.openAndWait();
webSocket.sendText("What do you want on your cheeseburger?");
client.flush();
validate();
stop();
}
代码示例来源:origin: advantageous/qbit
@Test
public void testText() throws Exception {
final int port = PortUtils.findOpenPortStartAt(4000);
final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build();
final AtomicReference<Object> bodyRef = new AtomicReference<>();
final AtomicReference<String> messageRef = new AtomicReference<>();
final CountDownLatch countDownLatch = new CountDownLatch(2);
httpServer.setWebSocketMessageConsumer(webSocketMessage -> {
bodyRef.set(webSocketMessage.body());
webSocketMessage.getSender().sendText("world");
countDownLatch.countDown();
});
httpServer.startServerAndWait();
final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();
final WebSocket webSocket = httpClient.createWebSocket("/foo");
webSocket.setTextMessageConsumer(message -> {
messageRef.set(message);
countDownLatch.countDown();
});
webSocket.openAndWait();
webSocket.sendText("hello");
countDownLatch.await(5, TimeUnit.SECONDS);
assertEquals("world", messageRef.get());
assertEquals("hello", bodyRef.get().toString());
}
代码示例来源:origin: advantageous/qbit
public static void main(String... args) {
final HttpClient httpClient = httpClientBuilder().setAutoFlush(true).setPort(9999).build();
httpClient.startClient();
final WebSocket webSocket = httpClient.createWebSocket("/hello");
webSocket.setTextMessageConsumer(message ->
puts("\n\n\n", message, "\n\n")
);
webSocket.openAndWait();
webSocket.sendText("Hello");
Sys.sleep(100000);
}
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNewOpenWaitWebSocket() {
connect();
server.setWebSocketMessageConsumer(webSocketMessage -> {
puts(webSocketMessage.address(), webSocketMessage.body());
if (webSocketMessage.getMessage().equals("What do you want on your cheeseburger?")) {
webSocketMessage.getSender().sendText("Bacon");
requestReceived.set(true);
} else {
puts("Websocket message", webSocketMessage.getMessage());
}
});
run();
final WebSocket webSocket = client.createWebSocket("/services/cheeseburger");
webSocket.setTextMessageConsumer(message -> {
if (message.equals("Bacon")) {
responseReceived.set(true);
}
});
webSocket.openAndWait();
webSocket.sendText("What do you want on your cheeseburger?");
client.flush();
validate();
stop();
}
代码示例来源:origin: advantageous/qbit
@Test
public void testWebSocket() {
connect();
server.setWebSocketMessageConsumer(webSocketMessage -> {
puts(webSocketMessage.address(), webSocketMessage.body());
if (webSocketMessage.getMessage().equals("What do you want on your cheeseburger?")) {
webSocketMessage.getSender().sendText("Bacon");
requestReceived.set(true);
} else {
puts("Websocket message", webSocketMessage.getMessage());
}
});
run();
final WebSocket webSocket = client.createWebSocket("/services/cheeseburger");
webSocket.setTextMessageConsumer(message -> {
if (message.equals("Bacon")) {
responseReceived.set(true);
}
});
webSocket.setOpenConsumer(
aVoid -> {
webSocket.sendText("What do you want on your cheeseburger?");
}
);
webSocket.open(e -> {
});
client.flush();
validate();
stop();
}
代码示例来源:origin: io.advantageous.qbit/qbit-core
private void wireWebSocket(final String serviceName, final String message) {
this.webSocket.setErrorConsumer(error -> {
if (error instanceof ConnectException) {
connected.set(false);
}
logger.error(sputs(this.getClass().getName(),
"::Exception calling WebSocket from client proxy",
"\nService Name", serviceName, "\nMessage", message), error);
});
//noinspection Convert2MethodRef
this.webSocket.setTextMessageConsumer(messageFromServer -> handleWebSocketReplyMessage(messageFromServer));
}
代码示例来源:origin: com.github.advantageous/qbit-core
private void wireWebSocket(final String serviceName, final String message) {
this.webSocket.setErrorConsumer(error ->
logger.error(sputs(this.getClass().getName(),
"::Exception calling WebSocket from client proxy", "\nService Name", serviceName, "\nMessage", message), error));
//noinspection Convert2MethodRef
this.webSocket.setTextMessageConsumer(messageFromServer -> handleWebSocketReplyMessage(messageFromServer));
}
代码示例来源:origin: advantageous/qbit
private void defaultWebSocketHandler(final WebSocket webSocket) {
webSocket.setTextMessageConsumer(webSocketMessageIn -> {
代码示例来源:origin: io.advantageous.qbit/qbit-core
public WebSocketTextQueue(final WebSocket webSocket, final int batchSize, final int flushInterval, final TimeUnit timeUnit) {
this.webSocket = webSocket;
this.stringQueue = QueueBuilder.queueBuilder().setBatchSize(batchSize).setPollWait(1000).build();
final SendQueue<String> sendQueue = this.stringQueue.sendQueueWithAutoFlush(flushInterval, timeUnit);
this.webSocket.setTextMessageConsumer(sendQueue::send);
}
代码示例来源:origin: io.advantageous.qbit/qbit-core
public WebSocketTextQueue(final WebSocket webSocket) {
this.webSocket = webSocket;
this.stringQueue = QueueBuilder.queueBuilder().setBatchSize(1).setLimit(100).setPollWait(1000).build();
final SendQueue<String> sendQueue = this.stringQueue.sendQueue();
this.webSocket.setTextMessageConsumer(sendQueue::send);
}
代码示例来源:origin: com.github.advantageous/qbit-core
private void defaultWebSocketHandler(final WebSocket webSocket) {
webSocket.setTextMessageConsumer(webSocketMessageIn -> {
代码示例来源:origin: io.advantageous.qbit/qbit-core
private void defaultWebSocketHandler(final WebSocket webSocket) {
webSocket.setTextMessageConsumer(webSocketMessageIn -> {
内容来源于网络,如有侵权,请联系作者删除!