To have more control on how many messages are consumed by each subscriber, you can use a polling configuration, thus polling for messages from the service at a fixed rate.
This behavior is achieved effectively by disabling prefetch by setting a fetchSize of zero. When using the polling mode, the connector always attempts to fetch 10 messages per request, where each request is done at the fixed rate defined by the pollingTime. No overlapping requests are executed and only one request per poll is handled by the service.
The syntax to listen for new messages from a queue at a fixed rate is:
<anypoint-mq:default-subscriber-config name="pollingConfig"
fetchSize="0"
pollingTime="1000"
acknowledgementTimeout="5000">
<anypoint-mq:connection url="${providerUrl}"
clientId="${clientId}"
clientSecret="${clientSecret}"/>
</anypoint-mq:default-subscriber-config>
<flow name="prefetchedListener">
<anypoint-mq:subscriber config-ref="pollingConfig" destination="${invoiceQueue}"/>
<!-- Message processing-->
</flow>
This source tries to retrieve 10 messages from the queue identified by the destination every 1 second,
and then dispatches each to the flow as a MuleMessage. In this case, the message remains in flight for 5 seconds.
By default, the message consumed is acknowledged only when the execution of the flow receiving the message finishes successfully.
If instead, an error occurs during the execution of the flow, the session is recovered and the message is redelivered.