當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpMessagingTemplate類代碼示例

本文整理匯總了Java中org.springframework.messaging.simp.SimpMessagingTemplate的典型用法代碼示例。如果您正苦於以下問題:Java SimpMessagingTemplate類的具體用法?Java SimpMessagingTemplate怎麽用?Java SimpMessagingTemplate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpMessagingTemplate類屬於org.springframework.messaging.simp包,在下文中一共展示了SimpMessagingTemplate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getWebSocketConsumersManager

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
/**
 * Manages kafka consumers running in a background processing thread for websocket consumers.
 * @param webKafkaConsumerFactory Factory for creating new Consumers
 * @param messagingTemplate messaging template instance for passing websocket messages.
 * @param backgroundConsumerExecutor The executor to run our manager in.
 * @param appProperties defined app properties.
 * @return manager instance for web socket consumers.
 */
@Bean
public WebSocketConsumersManager getWebSocketConsumersManager(
    final WebKafkaConsumerFactory webKafkaConsumerFactory,
    final SimpMessagingTemplate messagingTemplate,
    final TaskExecutor backgroundConsumerExecutor,
    final AppProperties appProperties) {

    // Create manager
    final WebSocketConsumersManager manager = new WebSocketConsumersManager(
        webKafkaConsumerFactory,
        messagingTemplate,
        appProperties.getMaxConcurrentWebSocketConsumers()
    );

    // Submit to executor service
    backgroundConsumerExecutor.execute(manager);

    return manager;
}
 
開發者ID:SourceLabOrg,項目名稱:kafka-webview,代碼行數:28,代碼來源:WebSocketConfig.java

示例2: SimpAnnotationMethodMessageHandler

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
/**
 * Create an instance of SimpAnnotationMethodMessageHandler with the given
 * message channels and broker messaging template.
 * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
 * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
 * @param brokerTemplate a messaging template to send application messages to the broker
 */
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
		MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {

	Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
	Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
	Assert.notNull(brokerTemplate, "brokerTemplate must not be null");

	this.clientInboundChannel = clientInboundChannel;
	this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
	this.brokerTemplate = brokerTemplate;

	Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:SimpAnnotationMethodMessageHandler.java

示例3: sendToNoAnnotations

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void sendToNoAnnotations() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "/dest", null);
	this.handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, inputMessage);

	verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
	assertEquals("sess1", accessor.getSessionId());
	assertEquals("/topic/dest", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.noAnnotationsReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:SendToMethodReturnValueHandlerTests.java

示例4: sendTo

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void sendTo() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	String sessionId = "sess1";
	Message<?> inputMessage = createInputMessage(sessionId, "sub1", null, null, null);
	this.handler.handleReturnValue(PAYLOAD, this.sendToReturnType, inputMessage);

	verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals("/dest1", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));

	accessor = getCapturedAccessor(1);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals("/dest2", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SendToMethodReturnValueHandlerTests.java

示例5: sendToDefaultDestination

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void sendToDefaultDestination() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	String sessionId = "sess1";
	Message<?> inputMessage = createInputMessage(sessionId, "sub1", "/app", "/dest", null);
	this.handler.handleReturnValue(PAYLOAD, this.sendToDefaultDestReturnType, inputMessage);

	verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals("/topic/dest", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToDefaultDestReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:SendToMethodReturnValueHandlerTests.java

示例6: testHeadersToSend

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void testHeadersToSend() throws Exception {
	Message<?> inputMessage = createInputMessage("sess1", "sub1", "/app", "/dest", null);

	SimpMessageSendingOperations messagingTemplate = Mockito.mock(SimpMessageSendingOperations.class);
	SendToMethodReturnValueHandler handler = new SendToMethodReturnValueHandler(messagingTemplate, false);

	handler.handleReturnValue(PAYLOAD, this.noAnnotationsReturnType, inputMessage);

	ArgumentCaptor<MessageHeaders> captor = ArgumentCaptor.forClass(MessageHeaders.class);
	verify(messagingTemplate).convertAndSend(eq("/topic/dest"), eq(PAYLOAD), captor.capture());

	MessageHeaders messageHeaders = captor.getValue();
	SimpMessageHeaderAccessor accessor = getAccessor(messageHeaders, SimpMessageHeaderAccessor.class);
	assertNotNull(accessor);
	assertTrue(accessor.isMutable());
	assertEquals("sess1", accessor.getSessionId());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.noAnnotationsReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:SendToMethodReturnValueHandlerTests.java

示例7: sendToUserSingleSession

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void sendToUserSingleSession() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	String sessionId = "sess1";
	TestUser user = new TestUser();
	Message<?> inputMessage = createInputMessage(sessionId, "sub1", null, null, user);
	this.handler.handleReturnValue(PAYLOAD, this.sendToUserSingleSessionReturnType, inputMessage);

	verify(this.messageChannel, times(2)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertEquals("/user/" + user.getName() + "/dest1", accessor.getDestination());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToUserSingleSessionReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));

	accessor = getCapturedAccessor(1);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals("/user/" + user.getName() + "/dest2", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToUserSingleSessionReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:SendToMethodReturnValueHandlerTests.java

示例8: sendToUserDefaultDestinationSingleSession

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void sendToUserDefaultDestinationSingleSession() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	String sessionId = "sess1";
	TestUser user = new TestUser();
	Message<?> inputMessage = createInputMessage(sessionId, "sub1", "/app", "/dest", user);
	this.handler.handleReturnValue(PAYLOAD, this.sendToUserSingleSessionDefaultDestReturnType, inputMessage);

	verify(this.messageChannel, times(1)).send(this.messageCaptor.capture());

	SimpMessageHeaderAccessor accessor = getCapturedAccessor(0);
	assertEquals(sessionId, accessor.getSessionId());
	assertEquals("/user/" + user.getName() + "/queue/dest", accessor.getDestination());
	assertEquals(MIME_TYPE, accessor.getContentType());
	assertNull("Subscription id should not be copied", accessor.getSubscriptionId());
	assertEquals(this.sendToUserSingleSessionDefaultDestReturnType, accessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:SendToMethodReturnValueHandlerTests.java

示例9: setup

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);

	Method method = this.getClass().getDeclaredMethod("getData");
	this.subscribeEventReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getDataAndSendTo");
	this.subscribeEventSendToReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handle");
	this.messageMappingReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getJsonView");
	this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SubscriptionMethodReturnValueHandlerTests.java

示例10: testMessageSentToChannel

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
public void testMessageSentToChannel() throws Exception {
	given(this.messageChannel.send(any(Message.class))).willReturn(true);

	String sessionId = "sess1";
	String subscriptionId = "subs1";
	String destination = "/dest";
	Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);

	this.handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);

	verify(this.messageChannel).send(this.messageCaptor.capture());
	assertNotNull(this.messageCaptor.getValue());

	Message<?> message = this.messageCaptor.getValue();
	SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.wrap(message);

	assertNull("SimpMessageHeaderAccessor should have disabled id", headerAccessor.getId());
	assertNull("SimpMessageHeaderAccessor should have disabled timestamp", headerAccessor.getTimestamp());
	assertEquals(sessionId, headerAccessor.getSessionId());
	assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
	assertEquals(destination, headerAccessor.getDestination());
	assertEquals(MIME_TYPE, headerAccessor.getContentType());
	assertEquals(this.subscribeEventReturnType, headerAccessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:SubscriptionMethodReturnValueHandlerTests.java

示例11: testHeadersPassedToMessagingTemplate

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testHeadersPassedToMessagingTemplate() throws Exception {
	String sessionId = "sess1";
	String subscriptionId = "subs1";
	String destination = "/dest";
	Message<?> inputMessage = createInputMessage(sessionId, subscriptionId, destination, null);

	MessageSendingOperations messagingTemplate = Mockito.mock(MessageSendingOperations.class);
	SubscriptionMethodReturnValueHandler handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	handler.handleReturnValue(PAYLOAD, this.subscribeEventReturnType, inputMessage);

	ArgumentCaptor<MessageHeaders> captor = ArgumentCaptor.forClass(MessageHeaders.class);
	verify(messagingTemplate).convertAndSend(eq("/dest"), eq(PAYLOAD), captor.capture());

	SimpMessageHeaderAccessor headerAccessor =
			MessageHeaderAccessor.getAccessor(captor.getValue(), SimpMessageHeaderAccessor.class);

	assertNotNull(headerAccessor);
	assertTrue(headerAccessor.isMutable());
	assertEquals(sessionId, headerAccessor.getSessionId());
	assertEquals(subscriptionId, headerAccessor.getSubscriptionId());
	assertEquals(this.subscribeEventReturnType, headerAccessor.getHeader(SimpMessagingTemplate.CONVERSION_HINT_HEADER));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:SubscriptionMethodReturnValueHandlerTests.java

示例12: setUp

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:UserRegistryMessageHandlerTests.java

示例13: HrMaxQuizService

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Autowired
public HrMaxQuizService(KieContainer kieContainer, SimpMessagingTemplate template) {
    
    log.info("Initialising a new quiz session.");
    
    this.kieSession = kieContainer.newKieSession("HrmaxSession");
    
    this.agendaEventPublisher = new PublishingAgendaEventListener(template);
    this.agendaEventListener = new LoggingAgendaEventListener();
    this.ruleRuntimeEventListener = new LoggingRuleRuntimeEventListener();

    this.kieSession.addEventListener(agendaEventPublisher);
    this.kieSession.addEventListener(agendaEventListener);
    this.kieSession.addEventListener(ruleRuntimeEventListener);
    
    this.kieSession.fireAllRules();
}
 
開發者ID:gratiartis,項目名稱:qzr,代碼行數:18,代碼來源:HrMaxQuizService.java

示例14: setup

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    this.deviceRegistry = new DeviceRegistry();

    this.brokerTemplateChannel = new TestMessageChannel();

    this.template = new SimpMessagingTemplate(this.brokerTemplateChannel);
    CompositeController controller = new CompositeController(sessionService,
            template, deviceRegistry);

    this.annotationMethodMessageHandler = new TestSimpAnnotationMethodMessageHandler(
            new TestMessageChannel(), new TestMessageChannel(), this.template);

    this.annotationMethodMessageHandler.registerHandler(controller);
    this.annotationMethodMessageHandler.setDestinationPrefixes(Arrays.asList("/app"));
    this.annotationMethodMessageHandler.setMessageConverter(new MappingJackson2MessageConverter());
    this.annotationMethodMessageHandler.setApplicationContext(new StaticApplicationContext());
    this.annotationMethodMessageHandler.afterPropertiesSet();

}
 
開發者ID:wieden-kennedy,項目名稱:composite-framework,代碼行數:22,代碼來源:StandaloneCompositeTests.java

示例15: EntityService

import org.springframework.messaging.simp.SimpMessagingTemplate; //導入依賴的package包/類
@Inject
public EntityService(EntityRepository entityRepository,
                     SimpMessagingTemplate simpMessagingTemplate,
                     PromptBuilder promptBuilder) {
    this.entityRepository = entityRepository;
    this.simpMessagingTemplate = simpMessagingTemplate;
    this.promptBuilder = promptBuilder;
}
 
開發者ID:scionaltera,項目名稱:emergentmud,代碼行數:9,代碼來源:EntityService.java


注:本文中的org.springframework.messaging.simp.SimpMessagingTemplate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。