Spring Integration将入站通道适配器提供给DB和Kafka

时间:2018-03-25 12:22:10

标签: spring-integration

我正在重构我的一些Spring Integration RSS feed代码,该代码使用feed入站通道适配器到微服务。我希望将feed存储在mongodb数据库内部(如果出现故障,审计等),并将feed(以JSON格式)写入kafka主题以进行后续处理。

如何使用Spring Integration执行此操作?我需要一个带有两个处理程序的pub / subscribe队列吗?

任何使用Java DSL的示例代码都会非常有用。

1 个答案:

答案 0 :(得分:0)

不确定是否需要pub / sub用于此类用例,但绝对可以在Feed Inbound Channel Adapter和Kafka Outbound Channel Adapter之间使用QueueChannelQueueChannel实际上可以提供MongoDbChannelMessageStore以便在出现故障时保持持久性。

Java DSL示例如下:

    @Bean
    public IntegrationFlow feedFlow(MongoDbChannelMessageStore messageStore) {
        return IntegrationFlows
                .from(Feed.inboundAdapter(...),
                        e -> e.poller(p -> p.fixedDelay(1000)))
                .channel(c -> c.queue(messageStore, "entries"))
                .handle(Kafka.outboundChannelAdapter(...), 
                        e -> e.poller(p -> p.fixedDelay(1000)))
                .get();
    }

https://docs.spring.io/spring-integration/docs/5.0.3.RELEASE/reference/html/feed.html#feed-java-configuration

https://docs.spring.io/spring-integration/docs/5.0.3.RELEASE/reference/html/mongodb.html#mongodb-priority-channel-message-store

https://docs.spring.io/spring-kafka/docs/2.1.4.RELEASE/reference/html/_spring_integration.html#si-outbound

相关问题