2016-05-05 6 views
2

私は非常に興味を持っているものの、春の統合をもっとしていますが、私の意見では奇妙な振る舞いがあります。今、それが唯一の可能性がされなければならない、私の理解では春の統合キューチャネルの容量が間違っている

<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket"> 
    <int:rendezvous-queue/> 
</int:channel> 

:私も同じ効果を持つランデブー・キューを試してみました

<int:channel id="ticketChannel" datatype="ch.elca.prototype.model.Ticket"> 
    <int:queue capacity="1"/> 
</int:channel> 

私はキューチャンネルを使用して簡単なアプリケーションを持っています1つのメッセージをそのチャネルで一度に移動します。たぶん2、あなたは1つの追加容量があると思う場合。私はそれを読む方法がわかりません。しかし、私はそのチャンネルに4回送ることができます。消費することなく、私には奇妙なビットがあり、それでは容量を理解できません。

、以下を参照してください。

主な用途:ここ を私は10枚の切符をストリーミングし、それぞれにopenTicketを呼び出す:

public static void main(final String[] args) throws InterruptedException { 
    try (ConfigurableApplicationContext context = SpringApplication.run(SassSimulatorApplication2.class, args)) { 
     final TicketGenerator generator = context.getBean(TicketGenerator.class); 
     final ProblemReporter reporter = context.getBean(ProblemReporter.class); 
     generator.createTickets().limit(10).forEach(reporter::openTicket); 
     context.close(); 
    } 
} 

ProblemReporter:

public class ProblemReporter { 
    private volatile QueueChannel channel; 

    public synchronized void openTicket(final Ticket ticket){ 
     final Message<Ticket> build = TicketMessageBuilder.buildMessage(ticket); 
     boolean send = channel.send(build); 

     System.out.println("send: " + send); 
     System.out.println("getQueueSize: " + channel.getQueueSize()); 
     System.out.println("getSendCount: " + channel.getSendCount()); 
     System.out.println("getReceiveCount: " + channel.getReceiveCount()); 
     System.out.println("getSendErrorCount: " + channel.getSendErrorCount()); 
     System.out.println("getRemainingCapacity: " + channel.getRemainingCapacity()); 
    } 

    @Value("#{ticketChannel}") 
    public void setChannel(final QueueChannel channel) { 
     this.channel = channel; 
    } 
} 

アプリケーションを起動すると、私は次のように:

send: true 
getQueueSize: 0 
getSendCount: 0 
getReceiveCount: 0 
getSendErrorCount: 0 
getRemainingCapacity: 1 

send: true 
getQueueSize: 0 
getSendCount: 0 
getReceiveCount: 0 
getSendErrorCount: 0 
getRemainingCapacity: 1 

send: true 
getQueueSize: 1 
getSendCount: 0 
getReceiveCount: 0 
getSendErrorCount: 0 
getRemainingCapacity: 0 

send: true 
getQueueSize: 1 
getSendCount: 0 
getReceiveCount: 0 
getSendErrorCount: 0 
getRemainingCapacity: 0 

私はSpring-Boot 1.3.3、Sprint-Integration 4.2.5.RELEASEを使用しています。また、Spring-Integration 4.1.9でSpring-Boot 1.2.8を試しました。

これは期待された動作ですか?

ありがとうございます。

答えて

1

channel.send(build, 30000);local変数に対して行われ、共有されていません。beanです。 私のテスト・ケースは、次のようになります。

QueueChannel channel = new QueueChannel(3); 

IntStream.range(0, 4) 
     .forEach(i -> { 
      boolean send = channel.send(new GenericMessage<>("test-" + i), 100); 
      System.out.println("send: " + send); 
      System.out.println("getQueueSize: " + channel.getQueueSize()); 
      System.out.println("getRemainingCapacity: " + channel.getRemainingCapacity()); 
     }); 

、結果は次のとおりです。

send: true 
getQueueSize: 1 
getRemainingCapacity: 2 
send: true 
getQueueSize: 2 
getRemainingCapacity: 1 
send: true 
getQueueSize: 3 
getRemainingCapacity: 0 
send: false 
getQueueSize: 3 
getRemainingCapacity: 0 

注:sendCount(および類似の)のみ@EnableIntegrationMBeanExportまたは@EnableIntegrationManagement経由で有効にすることができます。 リファレンスマニュアルのManagementを参照してください。

また、フレームワークの問題についていくつかのテストケースを見つけることができます。 QueueChannelTests

+0

返信ありがとうございました。私は共有ビーンでは何を意味するのか分かりません。私は上の私の授業でクラスを拡張しました。 @Valueでチャンネルを注入するので、Springによって管理されます。私が偶然の能力を、例えば、 50、その後、私は200にチャンネルを取得します... –

+0

OK。 Springブートアプリケーションのように見えるので、GitHubのどこかで共有すれば素晴らしいでしょう。そして、我々はそれをローカルで演奏します。 –

+0

本当にすみません、私は本当に愚かでした。私は既にトランスフォーマーを持っていたので、彼はすでにチケットを消費していました。とても恥ずかしい、助けてくれてありがとう。 –

関連する問題