Results 1 to 2 of 2

Thread: How to get the depth of a channel

  1. #1

    Default How to get the depth of a channel

    I am using a pollable channel in my java code as follows:

    ApplicationContext context = new ClassPathXmlApplicationContext("com.mydirectory/integration.xml");
    channel = (PollableChannel) context.getBean("annotatorChannel");

    Then in one of my methods, I do:

    channel.send(MessageBuilder.withPayload(auditEvent ).build());

    I want to check the depth of this channel before I execute the above line of code. Is there a way to do this?

    My integration.xml file has the following lines which are relevant to this:

    <int:channel id="annotatorChannel" datatype="com.mypackage.AuditEvent">
    <int:queue capacity="1000" />
    <int:interceptors>
    <int:ref bean="persistenceInterceptor"/>
    </int:interceptors>
    </int:channel>


    So is there a way in java code to see what depth ( or number of events) the queue has reached before I do:

    channel.send(MessageBuilder.withPayload(auditEvent ).build());

    as mentioned above.

    So basically I want to check the lenght of the channel(queue) and if it has exceeded 1000, then I want to throw an excpetion. Maybe something like this:

    if (channel.length >= 1000)
    throw exception;
    else
    channel.send(MessageBuilder.withPayload(auditEvent ).build());

    but I am not sure how to get the number of events currently in the channel queue.
    Last edited by albert_newton; May 9th, 2010 at 09:51 PM. Reason: Include more information

  2. #2

    Default

    I figured it out... I was previously using channel as a PollableChannel object. I changed it to use QueueChannel, and now I can use the getMesssageCount() method to determine the depth of the queue.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •