Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring集成中为Redis创建MessageSource_Java_Redis_Spring Integration - Fatal编程技术网

Java 在Spring集成中为Redis创建MessageSource

Java 在Spring集成中为Redis创建MessageSource,java,redis,spring-integration,Java,Redis,Spring Integration,我想配置InboundChannelAdapter,以便它能够从redis队列中弹出消息,并在基于Java的注释中将其传递给ServiceActivator(仅限于,更愿意避免使用XML)。我从Spring文档中找到了代码: @Bean("someAdapter.source") @EndpointId("someAdapter") @InboundChannelAdapter(channel = "channel3", poller = @Poller(fixedDelay = "5000")

我想配置InboundChannelAdapter,以便它能够从redis队列中弹出消息,并在基于Java的注释中将其传递给ServiceActivator(仅限于,更愿意避免使用XML)。我从Spring文档中找到了代码:

@Bean("someAdapter.source")
@EndpointId("someAdapter")
@InboundChannelAdapter(channel = "channel3", poller = @Poller(fixedDelay = "5000"))
public MessageSource<?> source() {
    return () -> {
        ...
    };
}
@Bean(“someAdapter.source”)
@EndpointId(“someAdapter”)
@InboundChannelAdapter(channel=“channel3”,poller=@poller(fixedDelay=“5000”))
public MessageSource源(){
返回()->{
...
};
}
但我不明白的是,如何使用redisConnectionFactory从redis队列中弹出数据来返回MessageSource

换句话说,如何在基于java的注释中做到这一点

  <int-redis:queue-inbound-channel-adapter id="postPublicationInboundAdapter"
                                             connection-factory="redisConnectionFactory"
                                             channel="postPublicationChannel"
                                             error-channel="postPublicationLoggingChannel"
                                             receive-timeout="5000"
                                             queue="archive.post.publication.queue"
                                             serializer="postPublicationJsonRedisSerializer"/>

让我们从这里开始:

通过XML配置和Spring集成命名空间支持,XML解析器隐藏了目标bean的声明和连接方式。对于Java&Annotation配置,了解目标最终用户应用程序的框架API非常重要

然后我们为该
打开一个XSD:


解释得很好。谢谢
 <xsd:element name="queue-inbound-channel-adapter">
    <xsd:annotation>
        <xsd:documentation>
            Defines a Message Producing Endpoint for the
            'org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint' for listening a Redis
            queue.
        </xsd:documentation>
    </xsd:annotation>
@Bean
RedisQueueMessageDrivenEndpoint redisQueueMessageDrivenEndpoint(RedisConnectionFactory redisConnectionFactory, RedisSerializer<?> serializer) {
    RedisQueueMessageDrivenEndpoint endpoint =
                new RedisQueueMessageDrivenEndpoint("archive.post.publication.queue", redisConnectionFactory);
    endpoint.setOutputChannelName("postPublicationChannel");
    endpoint.setErrorChannelName("postPublicationLoggingChannel");
    endpoint.setReceiveTimeout(5000);
    endpoint.setSerializer(serializer);
    return endpoint;
}