0

私は私がすべてのメッセージング操作を実行する別のクラスを持っているChannels.javaPollableChannelは

final String OUTPUT = "output"; 

    final String INPUT = "input"; 


    @Output(OUTPUT) 
    MessageChannel output(); 

    @BridgeFrom(OUTPUT) 
    PollableChannel input(); 

インタフェースを持っています交換してください。ここでPollableChannelを使用するにはどうすればいいですか?私は間違って何をしていますか?

EDIT

そして、どのように私は私の@Componentクラス内のBeanにアクセスしますか?

私は今、メッセージを受信するために、このチャネルを使用することができるようにしたい

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

と@Configurationクラスがありますか?

答えて

0

ブリッジは、インターフェイスメソッドのアノテーションでない@Beanである必要があります。the answer to your general question hereを参照してください。

EDIT

@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つのメッセージを削除し、それらを出力チャネルに送信します。

この例では、バインダーに送信されたメッセージを消費するウサギリスナーも追加されています。

+0

答えていただきありがとうございます。私はまだブリッジ用のBeanを作成し、@ BridgeFromにはChannels.OUTPUTを使用できますか? – usr1234

+0

はい。それはちょうど豆の名前です。 –

+0

親切に編集を参照してください – usr1234

関連する問題