Spring Cloud Stream 3.1发送事件

问题描述 投票:0回答:0

我正在将服务从 spring cloud stream 2.0 升级到 3.1

之前为了发布到我拥有的 Kinesis 流

@Component
public class KinesisStreamService {
    private final Log logger = LogFactory.getLog(this.getClass());
    private StreamProcessor orderOut;

    @Autowired
    public KinesisStreamService(StreamProcessor orderOut) {
        this.orderOut = orderOut;
    }

    public void send(String event) {
        if (event != null) {
            this.orderOut.ordersOut().send(new GenericMessage(event));
            this.logger.debug("Event sent KinesisInStreamServiceImpl : " + event);
        } else {
            throw new RuntimeException("Event can not be null");
        }
    }
}
@Service
public interface StreamProcessor {
    String INPUT = "ordersIn";

    @Output
    MessageChannel ordersOut();

    @Input
    SubscribableChannel ordersIn();
}

现在

@Ouput
在 3.1 中已经贬值以支持函数式编程

@EnableBinding @deprecated as of 3.1 支持函数式编程模型,提到创建 Supplier bean 喜欢

@Service
class PubSubSendQueue {
    @Bean
    public Supplier<String> output(){
        return Supplier { "Adam" }
    }
}

但是如果我需要在运行时将参数传递给 bean 定义函数,我将如何定义 Supplier bean bean 的延迟初始化是否是一个合适的解决方案。 有点像

    @Bean
    @Lazy
    public Supplier<GenericMessage> ordersOut(String event) {
        return () -> new GenericMessage(event);
    }
java spring spring-cloud spring-cloud-stream amazon-kinesis
© www.soinside.com 2019 - 2024. All rights reserved.