AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-642680

D-Dᴙum's questions

Martin Hope
D-Dᴙum
Asked: 2025-02-26 23:15:43 +0800 CST

与手动创建适配器相比,sourcePollingChannelAdapterSpec 中似乎忽略了 sendTimeout

  • 6

当我创建IntegrationFlow设置时sendTimeout(),值SourcePollingChannelAdapterSpec被忽略,导致轮询线程阻塞。如果我以编程方式创建,则不会SourcePollingChannelAdapter发生这种情况。例如,以编程方式使用@Configuration类:

@Configuration
public class JdbcPollingConfig {

    @Bean
    protected MessageChannel jdbcInboundChannel() {
        return new QueueChannel(1);
    }

    @Bean
    public ThreadPoolTaskScheduler jdbcTaskExecutor() {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        taskScheduler.setPoolSize(1);
        taskScheduler.initialize();
        return taskScheduler;
    }

    @Bean
    protected JdbcPollingChannelAdapter jdbcPollingChannelAdapter(final DataSource dataSource) {
        final JdbcPollingChannelAdapter adapter =
                new CustomJdbcPollingChannelAdapter(dataSource, "select dp_id, dp_payload from data_packets");
        return adapter;
    }

    @Bean
    protected SourcePollingChannelAdapter sourcePollingChannelAdapter(
            final JdbcPollingChannelAdapter adapter,
            final MessageChannel jdbcInboundChannel,
            final ThreadPoolTaskScheduler jdbcTaskExecutor) {
        final SourcePollingChannelAdapter spcAdapter = new SourcePollingChannelAdapter();
        spcAdapter.setSource(adapter);
        spcAdapter.setOutputChannel(jdbcInboundChannel);
        spcAdapter.setSendTimeout(500); // Sets the send-to-channel timeout - throws exception on timeout though.
        spcAdapter.setTaskScheduler(jdbcTaskExecutor);
        spcAdapter.setTrigger( new PeriodicTrigger(Duration.ofSeconds(2L)));
        return spcAdapter;
    }

}

请注意,该类CustomJdbcPollingChannelAdapter是我自己的,它只是进行了扩展,以便我可以doReceive()使用一些日志调用来覆盖该方法:

@Log4j2
public class CustomJdbcPollingChannelAdapter extends JdbcPollingChannelAdapter {
    public CustomJdbcPollingChannelAdapter(DataSource dataSource, String selectQuery) {
        super(dataSource, selectQuery);
    }

    public CustomJdbcPollingChannelAdapter(JdbcOperations jdbcOperations, String selectQuery) {
        super(jdbcOperations, selectQuery);
    }

    @Override
    protected Object doReceive() {
        log.info("Jdbc Polling.");
        return super.doReceive();
    }
}

在配置了通道队列的情况下,此配置会按预期抛出异常,因为没有通道的消费者jdbcInboundChannel。对比一下使用和IntegrationFlow配置:

@Configuration
public class JdbcDSLConfig {

    @Bean
    public QueueChannelSpec jdbcInboundChannel() {
        return MessageChannels.queue(1);
    }

    @Bean
    public MessageSource<Object> jdbcMessageSource(final DataSource dataSource) {
        return new CustomJdbcPollingChannelAdapter(dataSource, "select dp_id, dp_payload from data_packets");
    }

    @Bean
    public ThreadPoolTaskExecutor jdbcExecutor() {
        final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(1);
        taskExecutor.setMaxPoolSize(1);
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Bean
    public IntegrationFlow jdbcInboundFlow(final MessageSource<Object> jdbcMessageSource,
                                           final QueueChannelSpec jdbcInboundChannel,
                                           @Qualifier("jdbcExecutor") final ThreadPoolTaskExecutor jdbcExecutor) {
        return IntegrationFlow.from(jdbcMessageSource,
                        c -> c.poller(Pollers
                                .fixedDelay(2000)
                                .sendTimeout(1) // this has no effect.
                                .taskExecutor(jdbcExecutor)))
                .channel(jdbcInboundChannel)
                .get();

    }
}

即使在配置中设置了 sendTimeout,此配置也会在数据库的第二次轮询时阻塞。

spring
  • 1 个回答
  • 15 Views
Martin Hope
D-Dᴙum
Asked: 2024-12-08 07:05:48 +0800 CST

使用 Spring EL 或属性占位符动态设置 @Gateway 和 @ServiceActivator 的输入/输出通道

  • 5

@MessagingGateway允许defaultRequestChannel使用属性占位符${} 来设置注释:

@MessagingGateway(defaultRequestChannel = "${gateway.request.channel}")
public interface MessageGateway {

    @Gateway(requestTimeout = 2000)
    void sendListing(List<Path> entries);
}

但我无法对@Gateway注释进行类似操作:

@MessagingGateway
public interface MessageGateway {

    @Gateway(requestTimeout = 2000, requestChannel = "${gateway.request.channel}") // invalid
    void sendListing(List<Path> entries);
}

类似地,我无法使用属性占位符或 SpEl 动态设置 ServiceActivator inputChannel。outputChannel

我是否需要ServiceActivator使用手动配置ServiceActivatingHandler?

spring-integration
  • 1 个回答
  • 13 Views
Martin Hope
D-Dᴙum
Asked: 2023-10-24 21:52:06 +0800 CST

反应式变换函数的行为不符合预期

  • 5

当我提取各个步骤并单独执行它们时,我创建的反应器变换函数不会给出相同的结果。

我有包含价格类型列表的 DTO 记录。

public record CarrierDto(MetaData metaData, List<Daily> dailySeries) {

    public record MetaData(String name, String information) {};
    public record Daily(String date, Integer price) {};
}

Mono<CarrierDto>我想从a中提取Flux<Daily>然后将其转换为Flux<Price>.

@Table("price")
public record Price (
        @Column("p_date") String date,
        @Column("p_price") Integer price) {
}

为了进行这种转换,我有这个功能:

static Function<Mono<CarrierDto>, Flux<Price>> transform = carrierDtoMono ->
            carrierDtoMono.map(CarrierDto::dailySeries)
                    .flatMapMany(Flux::fromIterable)
                    .map(daily -> new Price(daily.date(), daily.price()));

然而,当我尝试使用此功能时,订阅时仅给出一个价格。如果我提取每个单独的步骤并执行提供的所有价格。例如这个测试类:

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

public class TestMain {

    static Function<Mono<CarrierDto>, Flux<Price>> transform = carrierDtoMono ->
            carrierDtoMono.map(CarrierDto::dailySeries)
                    .flatMapMany(Flux::fromIterable)
                    .map(daily -> new Price(daily.date(), daily.price()));

    public static void main(String[] args) {
        final CarrierDto dto = new CarrierDto(new CarrierDto.MetaData("Test", "Test information"),
                Arrays.asList(new CarrierDto.Daily("2023-01-01", 100),
                        new CarrierDto.Daily("2023-01-02", 101),
                        new CarrierDto.Daily("2023-01-03", 102),
                        new CarrierDto.Daily("2023-01-04", 103)));

        System.out.println("Using Transform function.");
        Mono.just(dto)
                .transform(transform)
                .subscribe(price -> System.out.println(String.format("Date: %s Price: %d", price.date(), price.price())));

        System.out.println("Without transform function.");

        final Mono<List<CarrierDto.Daily>> monoDailySeries = Mono.just(dto).map(CarrierDto::dailySeries);
        final Flux<CarrierDto.Daily> dailyFlux = monoDailySeries.flatMapMany(Flux::fromIterable);
        final Flux<Price> priceFlux = dailyFlux.map(daily -> new Price(daily.date(), daily.price()));

        priceFlux.subscribe(price -> System.out.println(String.format("Date: %s Price: %d", price.date(), price.price())));
    }
}

给出结果:

Using Transform function.
Date: 2023-01-01 Price: 100
Without transform function.
Date: 2023-01-01 Price: 100
Date: 2023-01-02 Price: 101
Date: 2023-01-03 Price: 102
Date: 2023-01-04 Price: 103

为什么结果不同?

java
  • 1 个回答
  • 20 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve