/** * Configure the {@code javaMailProperties} by invoking a {@link Consumer} callback which * is invoked with a {@link PropertiesBuilder}. * @param configurer the configurer. * @return the spec. * @see ImapMailReceiver#setJavaMailProperties(Properties) */ public ImapIdleChannelAdapterSpec javaMailProperties(Consumer<PropertiesBuilder> configurer) { PropertiesBuilder properties = new PropertiesBuilder(); configurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean IntegrationFlow consumer() { log.info("starting consumer.."); KafkaHighLevelConsumerMessageSourceSpec messageSourceSpec = Kafka.inboundChannelAdapter( new ZookeeperConnect(this.kafkaConfig.getZookeeperAddress())) .consumerProperties(props -> props.put("auto.offset.reset", "smallest") .put("auto.commit.interval.ms", "100")) .addConsumer("myGroup", metadata -> metadata.consumerTimeout(100) .topicStreamMap(m -> m.put(this.kafkaConfig.getTopic(), 1)) .maxMessages(10) .valueDecoder(String::new)); Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer = e -> e.poller(p -> p.fixedDelay(100)); return IntegrationFlows .from(messageSourceSpec, endpointConfigurer) .<Map<String, List<String>>>handle((payload, headers) -> { payload.entrySet().forEach(e -> log.info(e.getKey() + '=' + e.getValue())); return null; }) .get(); } }
@Bean(name = OUTBOUND_ID) IntegrationFlow producer() { log.info("starting producer flow.."); return flowDefinition -> { Consumer<KafkaProducerMessageHandlerSpec.ProducerMetadataSpec> producerMetadataSpecConsumer = (KafkaProducerMessageHandlerSpec.ProducerMetadataSpec metadata) -> metadata.async(true) .batchNumMessages(10) .valueClassType(String.class) .<String>valueEncoder(String::getBytes); KafkaProducerMessageHandlerSpec messageHandlerSpec = Kafka.outboundChannelAdapter(props -> props.put("queue.buffering.max.ms", "15000")) .messageKey(m -> m.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)) .addProducer(this.kafkaConfig.getTopic(), this.kafkaConfig.getBrokerAddress(), producerMetadataSpecConsumer); flowDefinition .handle(messageHandlerSpec); }; } }
/** * Configure the {@code javaMailProperties} by invoking a {@link Consumer} callback which * is invoked with a {@link PropertiesBuilder}. * @param configurer the configurer. * @return the spec. * @see AbstractMailReceiver#setJavaMailProperties(Properties) */ public S javaMailProperties(Consumer<PropertiesBuilder> configurer) { PropertiesBuilder properties = new PropertiesBuilder(); configurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean public IntegrationFlow newsFlow() { return IntegrationFlows.from(MessageChannels.queue("newsChannel", 10)) .<SyndEntry, String> transform( payload -> "《" + payload.getTitle() + "》 " + payload.getLink() + getProperty("line.separator")) .enrichHeaders( //1 Mail.headers() .subject("来自Spring的新闻") .to("wisely-man@126.com") .from("wisely-man@126.com")) .handle(Mail.outboundAdapter("smtp.126.com") //2 .port(25) .protocol("smtp") .credentials("wisely-man@126.com", "******") .javaMailProperties(p -> p.put("mail.debug", "false")), e -> e.id("smtpOut")) .get(); }
/** * Configure the {@code javaMailProperties} by invoking a {@link Consumer} callback which * is invoked with a {@link PropertiesBuilder}. * @param configurer the configurer. * @return the spec. * @see ImapMailReceiver#setJavaMailProperties(Properties) */ public ImapIdleChannelAdapterSpec javaMailProperties(Consumer<PropertiesBuilder> configurer) { PropertiesBuilder properties = new PropertiesBuilder(); configurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean public IntegrationFlow imapIdleFlow() { return IntegrationFlows .from(Mail.imapIdleAdapter("imap://user:pw@localhost:" + imapIdleServer.getPort() + "/INBOX") .autoStartup(true) .searchTermStrategy(this::fromAndNotSeenTerm) .userFlag("testSIUserFlag") .javaMailProperties(p -> p.put("mail.debug", "false") .put("mail.imap.connectionpoolsize", "5")) .shouldReconnectAutomatically(false) .headerMapper(mailHeaderMapper())) .channel(MessageChannels.queue("imapIdleChannel")) .get(); }
public MailSendingMessageHandlerSpec javaMailProperties(Consumer<PropertiesBuilder> propertiesConfigurer) { PropertiesBuilder properties = new PropertiesBuilder(); propertiesConfigurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean public IntegrationFlow imapMailFlow() { return IntegrationFlows .from(Mail.imapInboundAdapter("imap://user:pw@localhost:" + imapServer.getPort() + "/INBOX") .searchTermStrategy(this::fromAndNotSeenTerm) .userFlag("testSIUserFlag") .javaMailProperties(p -> p.put("mail.debug", "false")), e -> e.autoStartup(true) .poller(p -> p.fixedDelay(1000))) .channel(MessageChannels.queue("imapChannel")) .get(); }
/** * Configure the {@code javaMailProperties} by invoking a {@link Consumer} callback which * is invoked with a {@link PropertiesBuilder}. * @param configurer the configurer. * @return the spec. * @see AbstractMailReceiver#setJavaMailProperties(Properties) */ public S javaMailProperties(Consumer<PropertiesBuilder> configurer) { PropertiesBuilder properties = new PropertiesBuilder(); configurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean public IntegrationFlow pop3MailFlow() { return IntegrationFlows .from(Mail.pop3InboundAdapter("localhost", pop3Server.getPort(), "user", "pw") .javaMailProperties(p -> p.put("mail.debug", "false")) .headerMapper(mailHeaderMapper()), e -> e.autoStartup(true).poller(p -> p.fixedDelay(1000))) .enrichHeaders(s -> s.headerExpressions(c -> c.put(MailHeaders.SUBJECT, "payload.subject") .put(MailHeaders.FROM, "payload.from[0].toString()"))) .channel(MessageChannels.queue("pop3Channel")) .get(); }
public MailSendingMessageHandlerSpec javaMailProperties(Consumer<PropertiesBuilder> propertiesConfigurer) { PropertiesBuilder properties = new PropertiesBuilder(); propertiesConfigurer.accept(properties); return javaMailProperties(properties.get()); }
@Bean public IntegrationFlow sendMailFlow() { return IntegrationFlows.from("sendMailChannel") .enrichHeaders(Mail.headers() .subjectFunction(m -> "foo") .from("foo@bar") .toFunction(m -> new String[] { "bar@baz" })) .handle(Mail.outboundAdapter("localhost") .port(smtpServer.getPort()) .credentials("user", "pw") .protocol("smtp") .javaMailProperties(p -> p.put("mail.debug", "false")), e -> e.id("sendMailEndpoint")) .get(); }