本文整理汇总了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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}