Warm tip: This article is reproduced from serverfault.com, please click

MULE-4:VM: Check number of messages in VM queue before consuming

发布于 2020-12-08 10:25:32

We required to consume messages from VM in a flow. Currently it is throwing an error when VM is empty as below:

Message : Tried to consume messages from VM queue 'FQ' but it was empty after timeout of 5 SECONDS Payload Type : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider 

For now we wrapped it in try catch block and handling this error(still it is printing the error stack trace, we want to avoid it)

I want to check is there a way or piece of code that can be used for checking the number of messages available in VM before consuming it.

Questioner
Prudhvi B
Viewed
0
aled 2020-12-10 00:18:46

You can use the logException attribute on the error handler so the exception is not printed in the log.

Example:

    <try doc:name="Try">
        <vm:consume doc:name="Consume" config-ref="VM_Config" queueName="q1" />
        <error-handler >
            <on-error-continue enableNotifications="true" logException="false" doc:name="On Error Continue" type="VM:EMPTY_QUEUE">
                <logger level="INFO" doc:name="Logger" message="consume timeout"/>
            </on-error-continue>
        </error-handler>
    </try>