org.springframework.integration.dsl.support.Function Java Examples
The following examples show how to use
org.springframework.integration.dsl.support.Function.
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: WebSocketIntegration.java From building-microservices with Apache License 2.0 | 6 votes |
@Bean public IntegrationFlow webSocketFlow(EchoService echoService) { return (IntegrationFlowDefinition<?> integrationFlowDefinition) -> { Function<String, Object> splitter = (String messagePayload) -> { // convert the payload String echoValue = echoService.echo(messagePayload); // for each of the active WS sessions, // build a Message destined for that session containing the // input message return serverWebSocketContainer().getSessions().keySet().stream() .map(s -> MessageBuilder.withPayload(echoValue) .setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, s) .build()) .collect(Collectors.toList()); }; integrationFlowDefinition.split(String.class, splitter) .channel(c -> c.executor(Executors.newCachedThreadPool())) .handle(webSocketOutboundAdapter()); }; }
Example #2
Source File: OrderEntryProducerConfiguration.java From event-based-shopping-system with MIT License | 5 votes |
@Bean(name = OUTBOUND_ID) public IntegrationFlow producer() { log.info("starting producer flow.."); return flowDefinition -> { Consumer<KafkaProducerMessageHandlerSpec.ProducerMetadataSpec> producerMetadataSpecConsumer = ( KafkaProducerMessageHandlerSpec.ProducerMetadataSpec metadata) -> metadata .async(true).batchNumMessages(5) .valueClassType(String.class); Consumer<PropertiesBuilder> producerProperties = props -> props .put("queue.buffering.max.ms", "15000"); Function<Message<Object>, ?> messageKey = m -> m.getHeaders().get( IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER); KafkaProducerMessageHandlerSpec outboundChannelAdapter = Kafka .outboundChannelAdapter(producerProperties); String topic = this.kafkaConfig.getTopic(); String brokerAddress = this.kafkaConfig.getBrokerAddress(); KafkaProducerMessageHandlerSpec messageHandlerSpec = outboundChannelAdapter .messageKey(messageKey).addProducer(topic, brokerAddress, producerMetadataSpecConsumer); flowDefinition.handle(messageHandlerSpec); }; }