org.springframework.messaging.simp.SimpMessageSendingOperations Java Examples

The following examples show how to use org.springframework.messaging.simp.SimpMessageSendingOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: SimpAnnotationMethodMessageHandler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: SendToMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testHeadersToSend() throws Exception {
	Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);

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

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

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

	MessageHeaders headers = captor.getValue();
	SimpMessageHeaderAccessor accessor =
			MessageHeaderAccessor.getAccessor(headers, 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));
}
 
Example #4
Source File: SimpAnnotationMethodMessageHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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<>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
Example #5
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testHeadersToSend() throws Exception {
	Message<?> message = createMessage("sess1", "sub1", "/app", "/dest", null);

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

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

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

	MessageHeaders headers = captor.getValue();
	SimpMessageHeaderAccessor accessor =
			MessageHeaderAccessor.getAccessor(headers, 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));
}
 
Example #6
Source File: TailService.java    From spring4ws-demos with Apache License 2.0 5 votes vote down vote up
@Autowired
public TailService(@Value("${geoip2.cityfile}") String cityFile,
		@Value("${access.logs}") String accessLogs,
		SimpMessageSendingOperations messagingTemplate) {
	this.messagingTemplate = messagingTemplate;

	String databaseFile = cityFile;
	if (databaseFile != null) {
		Path database = Paths.get(databaseFile);
		if (Files.exists(database)) {
			try {
				this.reader = new DatabaseReader.Builder(database.toFile()).build();
			}
			catch (IOException e) {
				LoggerFactory.getLogger(getClass()).error("GeoIPCityService init", e);
			}
		}
	}

	this.tailers = new ArrayList<>();

	for (String logFile : accessLogs.split(",")) {
		Path p = Paths.get(logFile.trim());
		this.tailers.add(new Tailer(p.toFile(), new ListenerAdapter()));
	}

	this.executor = Executors.newFixedThreadPool(this.tailers.size());
	for (Tailer tailer : this.tailers) {
		this.executor.execute(tailer);
	}
}
 
Example #7
Source File: JoalMessageSendingTemplateTest.java    From joal with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldWrapMessageAndSend() {
    final SimpMessageSendingOperations sendingOperations = mock(SimpMessageSendingOperations.class);
    final JoalMessageSendingTemplate joalMessageSendingTemplate = new JoalMessageSendingTemplate(sendingOperations);

    final GlobalSeedStoppedPayload payload = new GlobalSeedStoppedPayload();
    joalMessageSendingTemplate.convertAndSend("/test", payload);

    final ArgumentCaptor<StompMessage> captor = ArgumentCaptor.forClass(StompMessage.class);

    verify(sendingOperations, times(1)).convertAndSend(eq("/test"), captor.capture());

    assertThat(captor.getValue().getType()).isEqualTo(StompMessageTypes.GLOBAL_SEED_STOPPED);
    assertThat(captor.getValue().getPayload()).isEqualTo(payload);
}
 
Example #8
Source File: OpenGamesForPlayerUpdatedPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 5 votes vote down vote up
@Inject
public OpenGamesForPlayerUpdatedPushNotificationHandler(LoginRepository loginRepository,
        OpenGameForPlayerRepository openGameForUserRepository, SimpMessageSendingOperations messagingTemplate) {
    this.loginRepository = loginRepository;
    this.openGameForUserRepository = openGameForUserRepository;
    this.messagingTemplate = messagingTemplate;
}
 
Example #9
Source File: WebSocketAnnotationMethodMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.applicationContext = new StaticApplicationContext();
	this.applicationContext.registerSingleton("controller", TestController.class);
	this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
	this.applicationContext.refresh();

	SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
	SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);

	this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
	this.messageHandler.setApplicationContext(this.applicationContext);
	this.messageHandler.afterPropertiesSet();
}
 
Example #10
Source File: WebSocketAnnotationMethodMessageHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.applicationContext = new StaticApplicationContext();
	this.applicationContext.registerSingleton("controller", TestController.class);
	this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
	this.applicationContext.refresh();

	SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
	SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);

	this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
	this.messageHandler.setApplicationContext(this.applicationContext);
	this.messageHandler.afterPropertiesSet();
}
 
Example #11
Source File: SimpAnnotationMethodMessageHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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<>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
Example #12
Source File: PeerStompService.java    From consensusj with Apache License 2.0 5 votes vote down vote up
@Inject
public PeerStompService(Context context,
                        PeerGroup peerGroup,
                        SimpMessageSendingOperations messagingTemplate) {
    this.peerGroup = peerGroup;
    this.context = context;
    this.messagingTemplate = messagingTemplate;
    //this.executorService = Executors.newFixedThreadPool(6, new ContextPropagatingThreadFactory("StompServiceListeners"));
    log.info("PeerStompService: Constructed with netparams: {}", context.getParams().getId());
}
 
Example #13
Source File: Application.java    From boot-examples with Apache License 2.0 5 votes vote down vote up
@Autowired
BookingRestController(
        @Qualifier("reservationPool") TaskScheduler taskScheduler,
        BookingRepository bookingRepository,
        SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
    this.taskScheduler = (taskScheduler);
    this.bookingRepository = bookingRepository;
}
 
Example #14
Source File: WebSocketAnnotationMethodMessageHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	this.applicationContext = new StaticApplicationContext();
	this.applicationContext.registerSingleton("controller", TestController.class);
	this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
	this.applicationContext.refresh();

	SubscribableChannel channel = Mockito.mock(SubscribableChannel.class);
	SimpMessageSendingOperations brokerTemplate = new SimpMessagingTemplate(channel);

	this.messageHandler = new TestWebSocketAnnotationMethodMessageHandler(brokerTemplate, channel, channel);
	this.messageHandler.setApplicationContext(this.applicationContext);
	this.messageHandler.afterPropertiesSet();
}
 
Example #15
Source File: WebSocketConfig.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
@Bean
public WebSocketConnectHandler<S> webSocketConnectHandler(SimpMessageSendingOperations messagingTemplate, ActiveWebSocketUserRepository repository) {
    return new WebSocketConnectHandler<>(messagingTemplate, repository);
}
 
Example #16
Source File: WebSocketHandlersConfig.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
public WebSocketDisconnectHandler<S> webSocketDisconnectHandler(SimpMessageSendingOperations messagingTemplate,
		ActiveWebSocketUserRepository repository) {
	return new WebSocketDisconnectHandler<>(messagingTemplate, repository);
}
 
Example #17
Source File: WebSocketConfig.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
@Bean
public WebSocketDisconnectHandler<S> webSocketDisconnectHandler(SimpMessageSendingOperations messagingTemplate, ActiveWebSocketUserRepository repository) {
    return new WebSocketDisconnectHandler<S>(messagingTemplate, repository);
}
 
Example #18
Source File: WebSocketHandlersConfig.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
public WebSocketConnectHandler<S> webSocketConnectHandler(SimpMessageSendingOperations messagingTemplate,
		ActiveWebSocketUserRepository repository) {
	return new WebSocketConnectHandler<>(messagingTemplate, repository);
}
 
Example #19
Source File: WebSocketAnnotationMethodMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public TestWebSocketAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
Example #20
Source File: MessageController.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Autowired
public MessageController(ActiveWebSocketUserRepository activeUserRepository,
		SimpMessageSendingOperations messagingTemplate) {
	this.activeUserRepository = activeUserRepository;
	this.messagingTemplate = messagingTemplate;
}
 
Example #21
Source File: WebSocketConnectHandler.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
public WebSocketConnectHandler(SimpMessageSendingOperations messagingTemplate, ActiveWebSocketUserRepository repository) {
    super();
    this.messagingTemplate = messagingTemplate;
    this.repository = repository;
}
 
Example #22
Source File: WebSocketDisconnectHandler.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
public WebSocketDisconnectHandler(SimpMessageSendingOperations messagingTemplate, ActiveWebSocketUserRepository repository) {
    super();
    this.messagingTemplate = messagingTemplate;
    this.repository = repository;
}
 
Example #23
Source File: SendUserPocketCardsPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public SendUserPocketCardsPushNotificationHandler(LoginRepository loginRepository,
        SimpMessageSendingOperations messagingTemplate) {
    this.loginRepository = loginRepository;
    this.messagingTemplate = messagingTemplate;
}
 
Example #24
Source File: TickActionOnTimerPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public TickActionOnTimerPushNotificationHandler(SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
}
 
Example #25
Source File: GameListUpdatedPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public GameListUpdatedPushNotificationHandler(GameListRepository gameListRepository,
        SimpMessageSendingOperations messagingTemplate) {
    this.gameListRepository = gameListRepository;
    this.messagingTemplate = messagingTemplate;
}
 
Example #26
Source File: OpenTableForUserPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public OpenTableForUserPushNotificationHandler(LoginRepository loginRepository,
        SimpMessageSendingOperations messagingTemplate) {
    this.loginRepository = loginRepository;
    this.messagingTemplate = messagingTemplate;
}
 
Example #27
Source File: ChatSentPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public ChatSentPushNotificationHandler(SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
}
 
Example #28
Source File: TableUpdatedPushNotificationHandler.java    From flex-poker with GNU General Public License v2.0 4 votes vote down vote up
@Inject
public TableUpdatedPushNotificationHandler(SimpMessageSendingOperations messagingTemplate,
        TableRepository tableRepository) {
    this.messagingTemplate = messagingTemplate;
    this.tableRepository = tableRepository;
}
 
Example #29
Source File: TwitterStatusListener.java    From spring4ws-demos with Apache License 2.0 4 votes vote down vote up
public TwitterStatusListener(SimpMessageSendingOperations messagingTemplate,
		Queue<Tweet> lastTweets) {
	this.messagingTemplate = messagingTemplate;
	this.lastTweets = lastTweets;
}
 
Example #30
Source File: TradeServiceImpl.java    From spring4ws-demos with Apache License 2.0 4 votes vote down vote up
@Autowired
public TradeServiceImpl(SimpMessageSendingOperations messagingTemplate,
		PortfolioService portfolioService) {
	this.messagingTemplate = messagingTemplate;
	this.portfolioService = portfolioService;
}