类org.springframework.messaging.simp.SimpMessageSendingOperations源码实例Demo

下面列出了怎么用org.springframework.messaging.simp.SimpMessageSendingOperations的API类实例代码及写法,或者点击链接到github查看源代码。

@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));
}
 
/**
 * 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);
}
 
@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));
}
 
/**
 * 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);
}
 
@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));
}
 
/**
 * 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);
}
 
@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();
}
 
@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();
}
 
源代码9 项目: joal   文件: JoalMessageSendingTemplateTest.java
@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);
}
 
@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();
}
 
源代码11 项目: consensusj   文件: PeerStompService.java
@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());
}
 
@Inject
public OpenGamesForPlayerUpdatedPushNotificationHandler(LoginRepository loginRepository,
        OpenGameForPlayerRepository openGameForUserRepository, SimpMessageSendingOperations messagingTemplate) {
    this.loginRepository = loginRepository;
    this.openGameForUserRepository = openGameForUserRepository;
    this.messagingTemplate = messagingTemplate;
}
 
源代码13 项目: boot-examples   文件: Application.java
@Autowired
BookingRestController(
        @Qualifier("reservationPool") TaskScheduler taskScheduler,
        BookingRepository bookingRepository,
        SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
    this.taskScheduler = (taskScheduler);
    this.bookingRepository = bookingRepository;
}
 
源代码14 项目: spring4ws-demos   文件: TailService.java
@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);
	}
}
 
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
	Assert.notNull(messagingTemplate, "'messagingTemplate' must not be null");
	this.messagingTemplate = messagingTemplate;
	this.annotationRequired = annotationRequired;
}
 
public TestSimpAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel,
		MessageChannel clientOutChannel, SimpMessageSendingOperations brokerTemplate) {

	super(clientInChannel, clientOutChannel, brokerTemplate);
}
 
public TestWebSocketAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
源代码19 项目: alchemy   文件: ActivityService.java
public ActivityService(SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
}
 
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
	Assert.notNull(messagingTemplate, "'messagingTemplate' must not be null");
	this.messagingTemplate = messagingTemplate;
	this.annotationRequired = annotationRequired;
}
 
public TestSimpAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel,
		MessageChannel clientOutChannel, SimpMessageSendingOperations brokerTemplate) {

	super(clientInChannel, clientOutChannel, brokerTemplate);
}
 
public TestWebSocketAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
源代码24 项目: TeamDojo   文件: ActivityService.java
public ActivityService(SimpMessageSendingOperations messagingTemplate) {
    this.messagingTemplate = messagingTemplate;
}
 
源代码25 项目: joal   文件: JoalMessageSendingTemplate.java
public JoalMessageSendingTemplate(final SimpMessageSendingOperations messageSendingOperations) {
    this.messageSendingOperations = messageSendingOperations;
}
 
public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) {
	Assert.notNull(messagingTemplate, "messagingTemplate must not be null");
	this.messagingTemplate = messagingTemplate;
	this.annotationRequired = annotationRequired;
}
 
public TestSimpAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel, MessageChannel clientOutChannel,
		SimpMessageSendingOperations brokerTemplate) {

	super(clientInChannel, clientOutChannel, brokerTemplate);
}
 
public TestWebSocketAnnotationMethodMessageHandler(SimpMessageSendingOperations brokerTemplate,
		SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel) {

	super(clientInboundChannel, clientOutboundChannel, brokerTemplate);
}
 
源代码30 项目: AxonBank   文件: BankAccountEventListener.java
@Autowired
public BankAccountEventListener(BankAccountRepository repository, SimpMessageSendingOperations messagingTemplate) {
    this.repository = repository;
    this.messagingTemplate = messagingTemplate;
}
 
 类方法
 同包方法