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


Java StompHeaderAccessor.setSubscriptionId方法代码示例

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


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

示例1: clientOutboundChannelUsedByAnnotatedMethod

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void clientOutboundChannelUsedByAnnotatedMethod() {
	TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
	SimpAnnotationMethodMessageHandler messageHandler = this.simpleBrokerContext.getBean(SimpAnnotationMethodMessageHandler.class);

	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
	headers.setSessionId("sess1");
	headers.setSessionAttributes(new ConcurrentHashMap<>());
	headers.setSubscriptionId("subs1");
	headers.setDestination("/foo");
	Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();

	messageHandler.handleMessage(message);

	message = channel.messages.get(0);
	headers = StompHeaderAccessor.wrap(message);

	assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
	assertEquals("/foo", headers.getDestination());
	assertEquals("bar", new String((byte[]) message.getPayload()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:MessageBrokerConfigurationTests.java

示例2: handleMessageToClientWithUserDestination

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithUserDestination() {

	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
	headers.setMessageId("mess0");
	headers.setSubscriptionId("sub0");
	headers.setDestination("/queue/foo-user123");
	headers.setNativeHeader(StompHeaderAccessor.ORIGINAL_DESTINATION, "/user/queue/foo");
	Message<byte[]> message = MessageBuilder.createMessage(EMPTY_PAYLOAD, headers.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(this.session, message);

	assertEquals(1, this.session.getSentMessages().size());
	WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
	assertTrue(((String) textMessage.getPayload()).contains("destination:/user/queue/foo\n"));
	assertFalse(((String) textMessage.getPayload()).contains(SimpMessageHeaderAccessor.ORIGINAL_DESTINATION));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:StompSubProtocolHandlerTests.java

示例3: clientOutboundChannelUsedBySimpleBroker

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void clientOutboundChannelUsedBySimpleBroker() {
	TestChannel channel = this.simpleBrokerContext.getBean("clientOutboundChannel", TestChannel.class);
	SimpleBrokerMessageHandler broker = this.simpleBrokerContext.getBean(SimpleBrokerMessageHandler.class);

	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
	headers.setSessionId("sess1");
	headers.setSubscriptionId("subs1");
	headers.setDestination("/foo");
	Message<?> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());

	// subscribe
	broker.handleMessage(message);

	headers = StompHeaderAccessor.create(StompCommand.SEND);
	headers.setSessionId("sess1");
	headers.setDestination("/foo");
	message = MessageBuilder.createMessage("bar".getBytes(), headers.getMessageHeaders());

	// message
	broker.handleMessage(message);

	message = channel.messages.get(0);
	headers = StompHeaderAccessor.wrap(message);

	assertEquals(SimpMessageType.MESSAGE, headers.getMessageType());
	assertEquals("/foo", headers.getDestination());
	assertEquals("bar", new String((byte[]) message.getPayload()));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:MessageBrokerConfigurationTests.java

示例4: handleMessageToClientWithBinaryWebSocketMessage

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void handleMessageToClientWithBinaryWebSocketMessage() {

	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.MESSAGE);
	headers.setMessageId("mess0");
	headers.setSubscriptionId("sub0");
	headers.setContentType(MimeTypeUtils.APPLICATION_OCTET_STREAM);
	headers.setDestination("/queue/foo");

	// Non-empty payload

	byte[] payload = new byte[1];
	Message<byte[]> message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(this.session, message);

	assertEquals(1, this.session.getSentMessages().size());
	WebSocketMessage<?> webSocketMessage = this.session.getSentMessages().get(0);
	assertTrue(webSocketMessage instanceof BinaryMessage);

	// Empty payload

	payload = EMPTY_PAYLOAD;
	message = MessageBuilder.createMessage(payload, headers.getMessageHeaders());
	this.protocolHandler.handleMessageToClient(this.session, message);

	assertEquals(2, this.session.getSentMessages().size());
	webSocketMessage = this.session.getSentMessages().get(1);
	assertTrue(webSocketMessage instanceof TextMessage);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:StompSubProtocolHandlerTests.java

示例5: createHeaders

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
public static StompHeaderAccessor createHeaders(String sessionId, String subscriptionId) {
    StompHeaderAccessor mha = StompHeaderAccessor.create(StompCommand.MESSAGE);
    mha.setLeaveMutable(true);
    mha.setMessageTypeIfNotSet(SimpMessageType.MESSAGE);
    mha.setSubscriptionId(subscriptionId);
    mha.setSessionId(sessionId);
    mha.setContentType(MimeTypeUtils.APPLICATION_JSON);
    return mha;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:10,代码来源:Stomp.java

示例6: getPositions

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
@Test
public void getPositions() throws Exception {

 StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
 headers.setSubscriptionId("0");
 headers.setDestination("/app/positions");
 headers.setSessionId("0");
 headers.setUser(new TestPrincipal("fabrice"));
 headers.setSessionAttributes(new HashMap<String, Object>());
 Message<byte[]> message = MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders());

 this.clientOutboundChannelInterceptor.setIncludedDestinations("/app/positions");
 this.clientInboundChannel.send(message);

 Message<?> reply = this.clientOutboundChannelInterceptor.awaitMessage(5);
 assertNotNull(reply);

 StompHeaderAccessor replyHeaders = StompHeaderAccessor.wrap(reply);
 assertEquals("0", replyHeaders.getSessionId());
 assertEquals("0", replyHeaders.getSubscriptionId());
 assertEquals("/app/positions", replyHeaders.getDestination());

 String json = new String((byte[]) reply.getPayload(), Charset.forName("UTF-8"));
 new JsonPathExpectationsHelper("$[0].company").assertValue(json, "Citrix Systems, Inc.");
 new JsonPathExpectationsHelper("$[1].company").assertValue(json, "Dell Inc.");
 new JsonPathExpectationsHelper("$[2].company").assertValue(json, "Microsoft");
 new JsonPathExpectationsHelper("$[3].company").assertValue(json, "Oracle");
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:29,代码来源:WebsocketTest.java

示例7: subscribe

import org.springframework.messaging.simp.stomp.StompHeaderAccessor; //导入方法依赖的package包/类
public void subscribe(String destination, String receiptId) {
	StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE);
	headers.setSubscriptionId("sub" + this.subscriptionIndex.getAndIncrement());
	headers.setDestination(destination);
	if (receiptId != null) {
		headers.setReceipt(receiptId);
	}
	sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build());
}
 
开发者ID:wieden-kennedy,项目名称:composite-framework,代码行数:10,代码来源:WebSocketStompSession.java


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