List of usage examples for org.springframework.messaging.support MessageBuilder withPayload
public static <T> MessageBuilder<T> withPayload(T payload)
From source file:demo.SampleSource.java
@Bean @InboundChannelAdapter(value = Source.SAMPLE, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1")) public MessageSource<String> timerMessageSource() { return new MessageSource<String>() { public Message<String> receive() { System.out.println("******************"); System.out.println("At the Source"); System.out.println("******************"); String value = "{\"value\":\"hi\"}"; System.out.println("Sending value: " + value); return MessageBuilder.withPayload(value).setHeader(MessageHeaders.CONTENT_TYPE, "application/json") .build();// w w w . j ava2 s . c o m } }; }
From source file:org.zrgs.spring.statemachine.cdplayer.CdPlayer.java
public void back() { stateMachine.sendEvent(MessageBuilder.withPayload(Application.Events.BACK) .setHeader(Application.Headers.TRACKSHIFT.toString(), -1).build()); }
From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java
@Test public void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception { // Arrange// w ww . j av a2 s . c o m ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Subject", "Hello"); jsonObject.put("Message", "World"); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter() .fromMessage(MessageBuilder.withPayload(payload).build(), null); // Assert assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest)); assertEquals("Hello", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getSubject()); assertEquals("World", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage()); }
From source file:io.pivotal.poc.dispatcher.MessageDispatcher.java
private String sendMessage(String topic, Object body, HttpHeaders requestHeaders) { MessageChannel channel = resolver.resolveDestination(topic + ".input"); MessageBuilder<?> builder = MessageBuilder.withPayload(body); builder.setHeader(MessageHeaders.CONTENT_TYPE, requestHeaders.getContentType()); for (Map.Entry<String, List<String>> entry : requestHeaders.entrySet()) { String headerName = entry.getKey(); if (requestHeadersToMap.contains(headerName)) { builder.setHeaderIfAbsent(headerName, StringUtils.collectionToCommaDelimitedString(entry.getValue())); }// w w w . j a v a 2s.co m } Message<?> message = builder.build(); channel.send(message); return message.getHeaders().getId().toString(); }
From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java
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);//from w w w . ja v a 2s .c o m } sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build()); }
From source file:fr.jugorleans.poker.client.stomp.WebSocketStompSession.java
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);/* w w w .j a v a 2 s .c o m*/ } sendInternal(MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build()); }
From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java
@Test public void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception { // Arrange/* www.jav a2s . com*/ ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Message", "World"); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter() .fromMessage(MessageBuilder.withPayload(payload).build(), null); // Assert assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest)); assertEquals("World", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage()); }
From source file:com.codeveo.lago.bot.stomp.client.WebSocketStompSession.java
public void disconnect() { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT); Message<byte[]> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build(); sendInternal(message);/*from www . j av a 2 s .c om*/ try { this.webSocketSession.close(CloseStatus.GOING_AWAY); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:fr.jugorleans.poker.client.stomp.WebSocketStompSession.java
public void disconnect() { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.DISCONNECT); Message<byte[]> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).setHeaders(headers).build(); sendInternal(message);//from ww w .j av a 2s .co m try { this.webSocketSession.close(); } catch (IOException e) { throw new IllegalStateException(e); } }