복붙노트

[REDIS] 봄 통합에 레디 스에 대한 MessageSource를 만들기

REDIS

봄 통합에 레디 스에 대한 MessageSource를 만들기

나는 (만 피하기 XML 선호) 그것은 레디 스 큐에서 메시지를 팝업 및 자바 기반의 주석에 ServiceActivator에 전달한다 그래서 InboundChannelAdapter을 구성 할. 나는 봄 문서의 코드를 발견 :

@Bean("someAdapter.source")
@EndpointId("someAdapter")
@InboundChannelAdapter(channel = "channel3", poller = @Poller(fixedDelay = "5000"))
public MessageSource<?> source() {
    return () -> {
        ...
    };
}

하지만 여기 이해하지 않는 무엇을, 어떻게 redisConnectionFactory를 사용하여 큐 레디 스로부터 데이터를 진열하여 MessageSource를 반환 할 수 있습니다?

즉, 어떻게 자바 기반의 주석에서이 작업을 수행 할 수 있습니다?

  <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"/>

해결법

  1. ==============================

    1.여기에서하자의 시작 : https://docs.spring.io/spring-integration/docs/5.0.9.RELEASE/reference/html/overview.html#programming-tips

    여기에서하자의 시작 : https://docs.spring.io/spring-integration/docs/5.0.9.RELEASE/reference/html/overview.html#programming-tips

    그런 다음 우리가에 대한 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>
    

    그래서, 그것은 INT-레디 스 같은 소리 : 큐 인바운드 채널 어댑터는 MessageSource를하지 않습니다. 따라서 @InboundChannelAdapter 막 다른 골목이다. 나는 XML 요소의 이름은 다음 잘못된 점에 동의하지만, 이름을 바꿀 너무 늦게 이미입니다.

    여기에서 우리는 또한 우리가 RedisQueueMessageDrivenEndpoint 다룰 필요가 있다고 생각했다. 그리고이기 때문에 메시지 구동, 자체 관리 우리가 이것에 대한 특별한 주석이 필요하지 않습니다. 이 같은 빈으로 선언하기 충분이있다 :

    @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;
    }
    
  2. from https://stackoverflow.com/questions/53407160/create-messagesource-for-redis-in-spring-integration by cc-by-sa and MIT license