-
May 9th, 2010, 09:26 PM
#1
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
-
May 12th, 2010, 02:08 PM
#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.
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
-
Forum Rules