Reputation: 97
I've a polling process in Mule that queries a MySQL database every 30 seconds and sends an email to a recipient. How do I limit to sending just 1 email regardless of the polling cycle whether it be 30 seconds or 15 seconds? I'm open to a counter in the mysql db as well if that's an option.
Thank you.
Upvotes: 0
Views: 312
Reputation: 24
You can put a vm queue in the end of your flow where the poller picks the data from the sql database.
In other flow, invoke the vm queue using a mule requester as an inbound connector inside a poll then set whatever frequency you want for the mail in the poll frequency using a cron expression or fixed-scheduler. Something like the below code:-
<flow name="db_poll">
<poll doc:name="Poll">
<db:no-operation-selected config-ref="" doc:name="Database"/>
</poll>
<logger message="invoking the database in the poll.. every 30 secs" level="INFO" doc:name="Logger"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="email_queue" connector-ref="VMformail" doc:name="VM"/>
</flow>
<flow name="email_poll">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1" timeUnit="DAYS"/>
<mulerequester:request-collection resource="VMformail" timeout="100000" doc:name="Mule Requester"/>
</poll>
<logger message="send an email" level="INFO" doc:name="Logger"/>
<smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
</flow>
Upvotes: 0
Reputation: 1942
You could use queueing(JMS) for your use case, before sending the "data" to jms would add a delay. You could do this like this
<message-properties-transformer overwrite="true" doc:name="Add DELAY in sending the Response to Queue">
<add-message-property key="Content_Type" value="application/json"/>
<add-message-property key="AMQ_SCHEDULED_DELAY" value="${aupost.retry.timeout}"/>
</message-properties-transformer>
Then add jms consumer to consume the message and send the email accordingly.
Upvotes: 1
Reputation: 148
Write a condition which will only send an email if emailSentFlag == false.
Use choice router to create the condition, and objectstore to hold the emailSentFlag value.
<flow...>
....
<objectstore:retrieve config-ref="ObjectStore__Configuration" key="emailSentFlag" defaultValue-ref="#[false]" targetProperty="flowVars.emailSentFlag" doc:name="retrieve emailSentFlag"/>
<choice doc:name="IsEmailSent?">
<when expression="#[flowVars.emailSentFlag == true]">
<logger level="INFO" doc:name="Log Email Already Sent"/>
</when>
<otherwise>
<smtp:outbound-endpoint host="" user="" password="" to="" from="" subject="test" cc="" bcc="" replyTo="" responseTimeout="10000" ref="Gmail" doc:name="SMTP" connector-ref="Gmail"/>
<objectstore:store config-ref="ObjectStore__Configuration" key="emailSentFlag" value-ref="#[true]" doc:name="store emailSentFlag"/>
</otherwise>
</choice>
</flow>
Also explore the TTL and Persistence feature of objectstore, it could be useful to you.
Cheers
Upvotes: 1
Reputation: 1401
Do you have any sample flow to show? You may be able to use collection/message aggregators but looking at flow first would help to suggest.
Upvotes: 0