本文整理汇总了Java中org.springframework.messaging.simp.stomp.StompSession类的典型用法代码示例。如果您正苦于以下问题:Java StompSession类的具体用法?Java StompSession怎么用?Java StompSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StompSession类属于org.springframework.messaging.simp.stomp包,在下文中一共展示了StompSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTracedWebsocketSession
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的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);
}
示例2: afterConnected
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
session.subscribe("/topic/greetings", this);
session.send("/app/hello", "{\"name\":\"Client\"}".getBytes());
log.info("New session: {}", session.getSessionId());
}
示例3: postProcessAfterInitialization
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof StompSession && !(bean instanceof PreservesHeadersStompSessionAdapter)) {
if (propagationProperties.getStomp().accept(beanName)) {
log.info("Context propagation enabled for stomp session [{}] on keys={}.", beanName, propagationProperties.getKeys());
return new PreservesHeadersStompSessionAdapter((StompSession) bean,
propagationProperties.buildEntriesFilter(),
propagationProperties.buildExtraStaticEntries(eurekaInstanceProperties));
} else {
log.debug("Context propagation disabled for stomp session [{}]", beanName);
}
}
return bean;
}
示例4: should_skip_stomp_session
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Test
public void should_skip_stomp_session() {
PropagationProperties propagationProperties = new PropagationProperties();
propagationProperties.getStomp().getExcludes().add(compile(beanName));
processor.setPropagationProperties(propagationProperties);
processor.setEurekaInstanceProperties(new EurekaInstanceProperties());
assertThat(processor.postProcessAfterInitialization(mock(StompSession.class), beanName).getClass(), not(equalTo(PreservesHeadersStompSessionAdapter.class)));
}
示例5: afterConnected
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void afterConnected(StompSession session,
StompHeaders connectedHeaders)
{
System.err.println("Connected! Headers:");
showHeaders(connectedHeaders);
subscribeTopic("/topic/messages", session);
sendJsonMessage(session);
}
示例6: main
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的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);
}
}
示例7: handleException
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void handleException(StompSession session, StompCommand command,
StompHeaders headers, byte[] payload, Throwable ex) {
if (errorHandler != null) {
errorHandler.handleError(new ProxySessionException(this, session, ex));
}
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:8,代码来源:ProxyWebSocketConnectionManager.java
示例8: unsubscribe
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
public void unsubscribe(String destination) {
StompSession.Subscription subscription = subscriptions.remove(destination);
if (subscription != null) {
connectIfNecessary();
subscription.unsubscribe();
}
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:8,代码来源:ProxyWebSocketConnectionManager.java
示例9: testConnect
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Test
public void testConnect() throws Exception {
try {
StompSession stompSession = stompClient.connect("ws://localhost:" + port + "/notifications", webSocketHttpHeaders, new StompSessionHandlerAdapter() {
}).get();
} catch (RuntimeException e) {
fail("Could not connect to endpoint notifications. " + e.getMessage());
}
}
示例10: handleException
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
exception.printStackTrace();
}
示例11: should_decorate_stomp_session
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Test
public void should_decorate_stomp_session() {
processor.setPropagationProperties(new PropagationProperties());
processor.setEurekaInstanceProperties(new EurekaInstanceProperties());
assertThat(processor.postProcessAfterInitialization(mock(StompSession.class), beanName).getClass(), equalTo(PreservesHeadersStompSessionAdapter.class));
}
示例12: handleException
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void handleException(StompSession s, StompCommand c, StompHeaders h, byte[] p, Throwable ex) {
this.failure.set(ex);
}
示例13: handleTransportError
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void handleTransportError(StompSession session, Throwable ex) {
this.failure.set(ex);
}
示例14: sendJsonMessage
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
private void sendJsonMessage(StompSession session)
{
ClientMessage msg = new ClientMessage(userId,
"hello from spring");
session.send("/app/chat/java", msg);
}
示例15: handleException
import org.springframework.messaging.simp.stomp.StompSession; //导入依赖的package包/类
@Override
public void handleException(StompSession s, StompCommand c, StompHeaders h, byte[] p, Throwable ex) {
this.failure.set(ex);
}