Announcement Announcement Module
No announcement yet.
How to get the depth of a channel Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:ref bean="persistenceInterceptor"/>

    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;
    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, 09:51 PM. Reason: Include more information

  • #2
    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.