Поллер интеграции Spring

avatar
Petr
1 июля 2021 в 18:59
134
1
0

Добрый день! Извините за мой плохой английский)

Я пытаюсь проверить работу с каналом опроса в интеграции Spring, но получаю ошибку: Когда я использую DirectChannel (без поллера), все хорошо, но когда я использую pollerChannel с очередью, я получаю ошибку.

@SpringBootApplication
public class IntegrationSysoutApplication {

    @Bean
    DirectChannel outputChannel() {
        return new DirectChannel();
    }

    @Bean
    PollableChannel pollerChannel() {
        return new QueueChannel();
    }

/*    @MessagingGateway
    public interface MyGateway {

        @Gateway(requestChannel = "animalFlow.input")
        void process(Animal animal);
    }*/


    @Bean
    public IntegrationFlow animalFlow() {
        return IntegrationFlows.from(pollerChannel(), x -> x.poller(Pollers.fixedRate(100)))
                .filter((GenericSelector<Animal>) animal -> !animal.getAnimalType().equals("cat"))
                .handle("bService", "process")
                .handle("cService", "process")
                .handle("aService", "process")
                .channel("outputChannel")
                .get();
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication
                .run(IntegrationSysoutApplication.class, args);
        DirectChannel outputChannel = ctx.getBean("outputChannel", DirectChannel.class);
        outputChannel
                .subscribe(message -> System.out.println("SUPER_MESSAGE: " + message));

        //Отправляем сообщение в gateway
       /* ctx.getBean(MyGateway.class).process(new Animal("lion"));
        ctx.getBean(MyGateway.class).process(new Animal("cat"));
        ctx.getBean(MyGateway.class).process(new Animal("penguin"));*/
       
        //Отправляем сообщение сразу в очередь потока, без gateway
        MessageChannel inputChannel = ctx.getBean("pollerChannel", PollableChannel.class);
        inputChannel.send(MessageBuilder.withPayload(new Animal("penguin")).build());
        inputChannel.send(MessageBuilder.withPayload(new Animal("cat")).build());
        inputChannel.send(MessageBuilder.withPayload(new Animal("dog")).build());

        ctx.close();
    }

}

и в этот момент я получаю ошибку и не могу добавить опросник для очереди:

IntegrationFlows.from(pollerChannel(), x -> x.poller(Pollers.fixedRate(100)))

Error:(47, 32) java: no suitable method found for from(java.lang.String,(x)->x.pol[...]100)))
    method org.springframework.integration.dsl.IntegrationFlows.from(java.lang.String,boolean) is not applicable...      

как я могу использовать Poller для pollingChannel в этой ситуации?

Источник

Ответы (1)

avatar
Gary Russell
1 июля 2021 в 19:30
1

Конфигурация опрашивающего устройства переходит к потребителю PollableChannel - в данном случае

.filter(...  e -> e.poller...)

Потребитель "опрашивает" канал на наличие новых сообщений.