具有春季集成的可轮询频道



我有一个接口通道.java

    final String OUTPUT = "output";
    final String INPUT = "input";

    @Output(OUTPUT)
    MessageChannel output();
    @BridgeFrom(OUTPUT)
    PollableChannel input();

我还有另一个类,在其中执行所有消息传递操作:

@Autowired
@Qualifier(Channels.OUTPUT)
private MessageChannel Output;

我可以很好地向交易所发送消息。如何在此处使用我的可投票频道?我做错了什么?

编辑

以及如何访问@Component类中的豆子?

我现在有@Configuration课

@Bean
@BridgeTo(Channels.OUTPUT)
public PollableChannel polled() {
    return new QueueChannel();
}

希望能够使用此通道接收消息?

桥接

器必须是接口方法上的@Bean而不是注释 - 请参阅此处的一般问题的答案。

编辑

@SpringBootApplication
@EnableBinding(Source.class)
public class So44018382Application implements CommandLineRunner {
    final Logger logger = LoggerFactory.getLogger(getClass());
    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext context = SpringApplication.run(So44018382Application.class, args);
        Thread.sleep(60_000);
        context.close();
    }
    @RabbitListener(bindings =
            @QueueBinding(value = @Queue(value = "foo", autoDelete = "true"),
                            exchange = @Exchange(value = "output", type = "topic"), key = "#"))
    // bind a queue to the output exchange
    public void listen(String in) {
        this.logger.info("received " + in);
    }
    @BridgeTo(value = Source.OUTPUT,
            poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "2"))
    @Bean
    public PollableChannel polled() {
        return new QueueChannel(5);
    }
    @Override
    public void run(String... args) throws Exception {
        for (int i = 0; i < 30; i++) {
            polled().send(new GenericMessage<>("foo" + i));
            this.logger.info("sent foo" + i);
        }
    }
}

这对我来说很好用;队列的深度为 5;当它已满时,发送方阻塞;轮询器一次只删除 2 条消息并将它们发送到输出通道。

此示例还添加一个兔子侦听器来使用发送到绑定程序的消息。

最新更新