Vijay Ram
Vijay Ram

Reputation: 325

dynamically determining polling frequency in mule

I have been struggling to find a work around to be able to dynamically read the polling frequency in mule flow. Currently I am reading that from a file using spring's Propertyplaceholder at the start up and value remains the same even if the fie is changed(as we all know)..

Since poll tag needs to be the first component in the flow, There is nothing much i could do to read the "live" file update.

Is there any way I could set the polling frequency dynamically read from a file(without requiring restart)?

For Reference:

<spring:beans>
        <context:property-placeholder location="file:///C:/Users/test/config.properties" />
</spring:beans> 

 <flow name="querying-database-pollingFlow1" doc:name="querying-database-pollingFlow1">
         <poll doc:name="Poll3e3">
            <fixed-frequency-scheduler frequency="${pollinginterval}"/>
            <db:select config-ref="MySQL_Configuration1" doc:name="Perform a query in MySQL">
                <db:dynamic-query><![CDATA[select empId,empName from employer where  status='active';]]></db:dynamic-query>
            </db:select>
         </poll>
....</flow>

Upvotes: 0

Views: 1702

Answers (3)

Pontus Ullgren
Pontus Ullgren

Reputation: 705

I would definitely advise against using hot deploy to solve this problem especially if you need to change the frequency often. There is a risk that this will lead to problems with permgen running out of memory.

Instead you could use a flow with a quartz endpoint that fires at a relatively low frequency. Then add a filter that only lets through the message at the required frequency.

The filter can either watch a properties file for changes or expose attributes over JMX to allow you to change the frequency. Something like this.

<spring:beans>
    <spring:bean id="frequencyFilter" class="FrequencyFilter" />
</spring:beans>

<flow name="trigger-polling-every-second" doc:name="trigger-polling-every-second">
    <quartz:inbound-endpoint repeatInterval="1000" doc:name="Quartz" responseTimeout="10000" jobName="poll-trigger">
        <quartz:event-generator-job>
            <quartz:payload>Scheduled Trigger</quartz:payload>
        </quartz:event-generator-job>
    </quartz:inbound-endpoint>
    <filter ref="frequencyFilter" />
    <vm:outbound-endpoint path="query-database" />
</flow>

<flow name="query-database">
    <vm:inbound-endpoint path="query-database" />
    <db:select config-ref="databaseConfig" doc:name="Perform a query in database">
       <db:dynamic-query><![CDATA[select empId,empName from employer where  status='active']]></db:dynamic-query>
    </db:select>
    <logger level="ERROR" message="#[payload]"/>
</flow>

Upvotes: 1

V&#237;ctor Romero
V&#237;ctor Romero

Reputation: 5115

The clean way using FixedFrequencyScheduler is not there. You could potentially go to the registry, fetch your flow by name, then get the MessageSource and cast it to FixedFrequencyScheduler set the new interval and stop-start, however if you take a look to the code you'll see there is no setter for it and reflexion it's just too dirty.

My first choice would probably be to leverage a quartz endpoint and then leverage the quartz abilities to expose the configuration throught jmx/rmi.

Upvotes: 1

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8321

There is absolutely no issue with <fixed-frequency-scheduler frequency="${pollinginterval}"/> as you can dynamically read polling frequency from a properties file ...

The only thing I am concern here is :- <context:property-placeholder location="file:///C:/Users/test/config.properties" />

Since you are reading from a properties file outside your classpath, better try with the following :-

<context:property-placeholder
        location="file:C:/Users/test/config.properties" />

One more thing .. if you are using Spring beans for properties file use the following way :-

<spring:beans>  
    <spring:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <spring:property name="locations">
         <spring:list>
          <spring:value>file:C:/Users/test/config.properties</spring:value>
         </spring:list>
       </spring:property>
     </spring:bean>
 </spring:beans>

Upvotes: 1

Related Questions