当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketStompClient.setMessageConverter方法代码示例

本文整理汇总了Java中org.springframework.web.socket.messaging.WebSocketStompClient.setMessageConverter方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketStompClient.setMessageConverter方法的具体用法?Java WebSocketStompClient.setMessageConverter怎么用?Java WebSocketStompClient.setMessageConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.socket.messaging.WebSocketStompClient的用法示例。


在下文中一共展示了WebSocketStompClient.setMessageConverter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);

    new Scanner(System.in).nextLine(); //Don't close immediately.
}
 
开发者ID:nielsutrecht,项目名称:spring-boot-websocket-client,代码行数:13,代码来源:ServiceClient.java

示例2: main

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
public static void main(String[] args) {
	DefaultSetting.setDefaultNetwork();
	if(args.length==0){
		OutputMessage.error("please enter parameter");
		return;
	}
	Map<String, String> params = parseParamsToMap(args);
	if(params==null){
		return;
	}
	// set host, port and websocket port
	DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
	final String address = params.get("address");
	final String WS_URI = DefaultSetting.getWsUri();
	// create WebSocket client
	List<Transport> transports = new ArrayList<Transport>(1);
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	WebSocketClient transport = new SockJsClient(transports);
	WebSocketStompClient stompClient = new WebSocketStompClient(transport);
	stompClient.setMessageConverter(new StringMessageConverter());
	StompSessionHandler handler = new WsMonitorMultisigHandler(address);
	stompClient.connect(WS_URI, handler);
	//block and monitor exit action
	ScannerUtil.monitorExit();
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:26,代码来源:ImplMonitorMultisigTransaction.java

示例3: main

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
public static void main(String[] args) {
	DefaultSetting.setDefaultNetwork();
	if(args.length==0){
		OutputMessage.error("please enter parameter");
		return;
	}
	Map<String, String> params = parseParamsToMap(args);
	if(params==null){
		return;
	}
	// set host, port and websocket port
	DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
	final String address = params.get("address");
	final String WS_URI = DefaultSetting.getWsUri();
	// create WebSocket client
	List<Transport> transports = new ArrayList<Transport>(1);
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	WebSocketClient transport = new SockJsClient(transports);
	WebSocketStompClient stompClient = new WebSocketStompClient(transport);
	stompClient.setMessageConverter(new StringMessageConverter());
	StompSessionHandler handler = new WsMonitorImcomingHandler(address);
	stompClient.connect(WS_URI, handler);
	//block and monitor exit action
	ScannerUtil.monitorExit();
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:26,代码来源:ImplMonitorIncomingTransaction.java

示例4: testTracedWebsocketSession

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
@Test
public void testTracedWebsocketSession()
    throws URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
  WebSocketStompClient stompClient = new WebSocketStompClient(
      new SockJsClient(createTransportClient()));
  stompClient.setMessageConverter(new MappingJackson2MessageConverter());

  StompSession stompSession = stompClient.connect(url, new StompSessionHandlerAdapter() {
  }).get(1, TimeUnit.SECONDS);

  stompSession.subscribe(SUBSCRIBE_GREETINGS_ENDPOINT, new GreetingStompFrameHandler());
  stompSession.send(SEND_HELLO_MESSAGE_ENDPOINT, new HelloMessage("Hi"));

  // Three spans related to the websocket session, and two related to websocket connect
  await().until(() -> mockTracer.finishedSpans().size() == 5);

  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(SEND_HELLO_MESSAGE_ENDPOINT)).toArray().length == 1);
  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(SUBSCRIBE_GREETINGS_ENDPOINT)).toArray().length == 1);
  assertTrue(mockTracer.finishedSpans().stream().filter(s ->
      s.operationName().equals(GreetingController.DOING_WORK)).toArray().length == 1);
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:24,代码来源:SpringWebsocketTracingTest.java

示例5: stompClient

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(MessageConverter messageConverter,
                                        ThreadPoolTaskScheduler taskScheduler) {
    int bufferSizeLimit = 1024 * 1024 * 8;

    StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient client = new WebSocketStompClient(sockJsClient);
    client.setInboundMessageSizeLimit(bufferSizeLimit);
    client.setMessageConverter(messageConverter);
    client.setTaskScheduler(taskScheduler);
    client.setDefaultHeartbeat(new long[]{0, 0});
    return client;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:18,代码来源:ZuulWebSocketConfiguration.java

示例6: main

import org.springframework.web.socket.messaging.WebSocketStompClient; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception
   {
WebSocketClient simpleWebSocketClient =
    new StandardWebSocketClient();
List<Transport> transports = new ArrayList<>(1);
transports.add(new WebSocketTransport(simpleWebSocketClient));

SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient =
    new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());

String url = "ws://localhost:9090/chat";
String userId = "spring-" +
    ThreadLocalRandom.current().nextInt(1, 99);
StompSessionHandler sessionHandler = new MyStompSessionHandler(userId);
StompSession session = stompClient.connect(url, sessionHandler)
    .get();
BufferedReader in =
    new BufferedReader(new InputStreamReader(System.in));
for (;;) {
    System.out.print(userId + " >> ");
    System.out.flush();
    String line = in.readLine();
    if ( line == null ) break;
    if ( line.length() == 0 ) continue;
    ClientMessage msg = new ClientMessage(userId, line);
    session.send("/app/chat/java", msg);
}
   }
 
开发者ID:jaysridhar,项目名称:spring-websocket-client,代码行数:31,代码来源:Application.java


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