• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WebSocketMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.web.reactive.socket.WebSocketMessage的典型用法代码示例。如果您正苦于以下问题:Java WebSocketMessage类的具体用法?Java WebSocketMessage怎么用?Java WebSocketMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WebSocketMessage类属于org.springframework.web.reactive.socket包,在下文中一共展示了WebSocketMessage类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
	return session
		.receive()
		.log("inbound-incoming-chat-message")
		.map(WebSocketMessage::getPayloadAsText)
		.log("inbound-convert-to-text")
		.map(s -> session.getId() + ": " + s)
		.log("inbound-mark-with-session-id")
		.flatMap(this::broadcast)
		.log("inbound-broadcast-to-broker")
		.then();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:14,代码来源:InboundChatService.java


示例2: main

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
public static void main(String[] args) throws URISyntaxException {
		WebSocketClient client = new ReactorNettyWebSocketClient();		
		client.execute(URI.create(BITFINEX), 
				session -> session.send(Mono.just(session.textMessage("{\"event\": \"subscribe\", \"channel\": \"ticker\", \"pair\": \"BTCUSD\" }")))
//				.and(session.send(Mono.just(session.textMessage("{\"event\": \"subscribe\", \"channel\": \"ticker\", \"pair\": \"ETHUSD\" }"))))
//				.and(session.send(Mono.just(session.textMessage("{\"event\": \"subscribe\", \"channel\": \"ticker\", \"pair\": \"LTCUSD\" }"))))
//				.and(session.send(Mono.just(session.textMessage("{\"event\": \"subscribe\", \"channel\": \"ticker\", \"pair\": \"XRPUSD\" }"))))				
			    .thenMany(session
			    	      .receive()
			    	      .map(WebSocketMessage::getPayloadAsText)
			    	      .filter(msg -> msg.indexOf("\"hb\"") < 0)
			    	      .map(msg -> {
			    	    	  	String[] strs = msg.replace(']', ' ').trim().split(",");
			    	    	  	if(strs.length > 9) {
//			    	    	  		System.out.println(strs[1]+" "+strs[2]+" "+strs[3]+" "+strs[4]+" "+strs[5]+" "+strs[6]+" "+strs[7]+" "+strs[8]+" "+strs[9]+" "+strs[10]);
			    	    	  		BigDecimal mid = (new BigDecimal(strs[9]).add(new BigDecimal(strs[10].trim()))).divide(BigDecimal.valueOf(2));
			    	    	  		QuoteBf qbf = new QuoteBf(mid, new BigDecimal(strs[1]), new BigDecimal(strs[3]), new BigDecimal(strs[7]), new BigDecimal(strs[10]), new BigDecimal(strs[9]), new BigDecimal(strs[8]), "");
			    	    	  		qbf.setPair("BTCUSD");
			    	    	  		return Optional.of(qbf);
			    	    	  	}
								return Optional.empty();
						})			    	      
			    	      .log())
			    	    .then()).block();		
		System.out.println("End");
	}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:27,代码来源:WebsocketClient.java


示例3: handlerMapping

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Bean
public HandlerMapping handlerMapping() {
    Map<String, WebSocketHandler> mappings = new HashMap<>(2);
    mappings.put("/in", session -> {
        session.receive()
            .map(WebSocketMessage::getPayloadAsText)
            .log()
            .subscribe(out::onNext);

        return session.send(Mono.just(session.textMessage(MESSAGE_HELLO))).then(session.send(in.map(session::textMessage)));
    });

    mappings.put("/out", session -> {
        session.receive()
            .map(WebSocketMessage::getPayloadAsText)
            .log()
            .subscribe();

        return session.send(Mono.just(session.textMessage(MESSAGE_HELLO))).then(session.send(out.map(session::textMessage)));
    });

    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setUrlMap(mappings);
    mapping.setOrder(10);
    return mapping;
}
 
开发者ID:pzmi,项目名称:webflux-websocket-server,代码行数:27,代码来源:Websocket.java


示例4: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
	// pass headers along so custom headers can be sent through
	return client.execute(url, this.headers, new WebSocketHandler() {
		@Override
		public Mono<Void> handle(WebSocketSession proxySession) {
			// Use retain() for Reactor Netty
			Mono<Void> proxySessionSend = proxySession
					.send(session.receive().doOnNext(WebSocketMessage::retain));
					// .log("proxySessionSend", Level.FINE);
			Mono<Void> serverSessionSend = session
					.send(proxySession.receive().doOnNext(WebSocketMessage::retain));
					// .log("sessionSend", Level.FINE);
			return Mono.when(proxySessionSend, serverSessionSend).then();
		}

		/**
		 * Copy subProtocols so they are available downstream.
		 * @return
		 */
		@Override
		public List<String> getSubProtocols() {
			return ProxyWebSocketHandler.this.subProtocols;
		}
	});
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:27,代码来源:WebsocketRoutingFilter.java


示例5: echo

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Test
public void echo() throws Exception {
	int count = 100;
	Flux<String> input = Flux.range(1, count).map(index -> "msg-" + index);
	ReplayProcessor<Object> output = ReplayProcessor.create(count);

	client.execute(getUrl("/echo"),
			session -> {
				logger.debug("Starting to send messages");
				return session
						.send(input.doOnNext(s -> logger.debug("outbound " + s)).map(session::textMessage))
						.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
						.subscribeWith(output)
						.doOnNext(s -> logger.debug("inbound " + s))
						.then()
						.doOnSuccessOrError((aVoid, ex) ->
								logger.debug("Done with " + (ex != null ? ex.getMessage() : "success")));
			})
			.block(Duration.ofMillis(5000));

	assertEquals(input.collectList().block(Duration.ofMillis(5000)),
			output.collectList().block(Duration.ofMillis(5000)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:24,代码来源:WebSocketIntegrationTests.java


示例6: doHandle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
protected Mono<Void> doHandle(WebSocketSession session) {
	//end::code[]
	return session.receive()
		.log(session.getId()
			+ "-inbound-incoming-chat-message")
		.map(WebSocketMessage::getPayloadAsText)
		.log(session.getId()
			+ "-inbound-convert-to-text")
		.flatMap(message -> broadcast(message, session))
		.log(session.getId()
			+ "-inbound-broadcast-to-broker")
		.then();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:15,代码来源:InboundChatService.java


示例7: handleInternal

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
protected Mono<Void> handleInternal(WebSocketSession session) {
	return session
		.receive()
		.log(getUser(session.getId())
			+ "-inbound-incoming-chat-message")
		.map(WebSocketMessage::getPayloadAsText)
		.log(getUser(session.getId())
			+ "-inbound-convert-to-text")
		.flatMap(message ->
			broadcast(message, getUser(session.getId())))
		.log(getUser(session.getId())
			+ "-inbound-broadcast-to-broker")
		.then();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:16,代码来源:InboundChatService.java


示例8: main

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
public static final void main(String[] args) throws URISyntaxException {

        WebSocketClient client = new ReactorNettyWebSocketClient();
//        client.execute(new URI("ws://localhost:8080/echo"), (WebSocketSession session) -> {
//            session.send().log().;
//        });
        
        int count = 100;
		Flux<String> input = Flux.range(1, count).map(index -> "msg-" + index);
		ReplayProcessor<Object> output = ReplayProcessor.create(count);

		client.execute(new URI("ws://localhost:8080/echo"),
				session -> {
					log.debug("Starting to send messages");
					return session
							.send(input.doOnNext(s -> log.debug("outbound " + s)).map(session::textMessage))
							.thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText))
							.subscribeWith(output)
							.doOnNext(s -> log.debug("inbound " + s))
							.then()
							.doOnTerminate((aVoid, ex) ->
									log.debug("Done with " + (ex != null ? ex.getMessage() : "success")));
				})
				.block(Duration.ofMillis(5000));

//		assertEquals(input.collectList().block(Duration.ofMillis(5000)),
//				output.collectList().block(Duration.ofMillis(5000)));
//        client.execute(new URI("ws://localhost:8080/echo")), session -> {
//            session.
//        }
//        ).blockMillis(5000);
    }
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:33,代码来源:WebSocketDemoClient.java


示例9: main

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
	WebSocketClient client = new ReactorNettyWebSocketClient();		
	client.execute(URI.create("wss://echo.websocket.org"), 
			session -> session.send(Mono.just(
					session.textMessage("{\"event\":\"ping\"}")))
		    .thenMany(session
		    	      .receive()
		    	      .map(WebSocketMessage::getPayloadAsText)
		    	      .log())
		    	    .then()).block(Duration.ofSeconds(10));		
	System.out.println("End");
}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:13,代码来源:WsClient.java


示例10: subProtocol

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Test
public void subProtocol() throws Exception {
	String protocol = "echo-v1";
	AtomicReference<HandshakeInfo> infoRef = new AtomicReference<>();
	MonoProcessor<Object> output = MonoProcessor.create();

	client.execute(getUrl("/sub-protocol"),
			new WebSocketHandler() {
				@Override
				public List<String> getSubProtocols() {
					return Collections.singletonList(protocol);
				}
				@Override
				public Mono<Void> handle(WebSocketSession session) {
					infoRef.set(session.getHandshakeInfo());
					return session.receive()
							.map(WebSocketMessage::getPayloadAsText)
							.subscribeWith(output)
							.then();
				}
			})
			.block(Duration.ofMillis(5000));

	HandshakeInfo info = infoRef.get();
	assertThat(info.getHeaders().getFirst("Upgrade"), Matchers.equalToIgnoringCase("websocket"));
	assertEquals(protocol, info.getHeaders().getFirst("Sec-WebSocket-Protocol"));
	assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol());
	assertEquals("Wrong protocol detected on the server side", protocol, output.block(Duration.ofMillis(5000)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:30,代码来源:WebSocketIntegrationTests.java


示例11: customHeader

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Test
public void customHeader() throws Exception {
	HttpHeaders headers = new HttpHeaders();
	headers.add("my-header", "my-value");
	MonoProcessor<Object> output = MonoProcessor.create();

	client.execute(getUrl("/custom-header"), headers,
			session -> session.receive()
					.map(WebSocketMessage::getPayloadAsText)
					.subscribeWith(output)
					.then())
			.block(Duration.ofMillis(5000));

	assertEquals("my-header:my-value", output.block(Duration.ofMillis(5000)));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:16,代码来源:WebSocketIntegrationTests.java


示例12: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
	String protocol = session.getHandshakeInfo().getSubProtocol();
	if (!StringUtils.hasText(protocol)) {
		return Mono.error(new IllegalStateException("Missing protocol"));
	}
	WebSocketMessage message = session.textMessage(protocol);
	return doSend(session, Mono.just(message));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:10,代码来源:WebSocketIntegrationTests.java


示例13: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
    // Use retain() for Reactor Netty
    return session.send(session.receive().doOnNext(WebSocketMessage::retain));
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:6,代码来源:EchoWebSocketHandler.java


示例14: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
    String protocol = session.getHandshakeInfo().getSubProtocol();
    WebSocketMessage message = session.textMessage(this.posts.findAll().takeLast(0).toString());
    return doSend(session, Mono.just(message));
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:7,代码来源:PostsWebSocketHandler.java


示例15: doSend

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
private Mono<Void> doSend(WebSocketSession session, Publisher<WebSocketMessage> output) {
    return session.send(Mono.delay(Duration.ofMillis(100)).thenMany(output));
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:4,代码来源:PostsWebSocketHandler.java


示例16: convert

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
public static QuoteBs convert(WebSocketMessage msg) {
//		return msg.getPayloadAsText()
		return null;
	}
 
开发者ID:Angular2Guy,项目名称:AngularAndSpring,代码行数:5,代码来源:QuoteHandler.java


示例17: doSend

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
private static Mono<Void> doSend(WebSocketSession session, Publisher<WebSocketMessage> output) {
	return session.send(output);
	// workaround for suspected RxNetty WebSocket client issue
	// https://github.com/ReactiveX/RxNetty/issues/560
	// return session.send(Mono.delay(Duration.ofMillis(100)).thenMany(output));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:7,代码来源:WebSocketIntegrationTests.java


示例18: handle

import org.springframework.web.reactive.socket.WebSocketMessage; //导入依赖的package包/类
@Override
public Mono<Void> handle(WebSocketSession session) {
	// Use retain() for Reactor Netty
	return session.send(session.receive().doOnNext(WebSocketMessage::retain).delay(Duration.ofSeconds(2)));
}
 
开发者ID:sdeleuze,项目名称:spring-reactive-playground,代码行数:6,代码来源:EchoWebSocketHandler.java



注:本文中的org.springframework.web.reactive.socket.WebSocketMessage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IASTStatement类代码示例发布时间:2022-05-22
下一篇:
Java TelemetryConfiguration类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap