This is a pretty generic question, but I can give you some outlining hints regarding the scheduling using Spring:
Include in your dependencies the Spring Context Support package if you don't already have it. If you're using Maven then you can find the dependency here.
Create a org.quartz.Job implementation that does the actual sending of the mail. I would use the Spring-provided QuartzJobBean. NOTE: There is actually a org.quartz.jobs.ee.mail.SendMailJob class that does mail sending. In both cases you can retrieve the data from your ActiveMQ instance and generate the desired content for the mail.
public class SendMailFromActiveMQ extends QuartzJobBean { @Override protected void doExecuteInternal(ApplicationContext applicationContext, JobExecutionContext jobExecutionContext) { //generate content for email //send email }
}
Attach your org.quartz.Job implementation to a JobDetailBean bean in your application context definition:
<bean id="sendEmailJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="ro.oneandone.hosting.ebusiness.nlt.sending.quartz.SendRegularMessagesJob" />
</bean>
- Create a CronTrigger for the previous JobDetailBean bean:
<bean id="sendEmailCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="sendEmailJob" />
<property name="cronExpression" value="0 0 0/1 * * ?" />
<!-- Run every hour -->
</bean>
- To finalize, you register the job to a SchedulerFactoryBean:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="sendEmailCronTrigger"/>
</list>
</property>
</bean>
I repeat, this is just an outline. you have to adapt the code to your needs, which I hope i understood correctly, since you tagged this question with "Spring".
If you need the following links are for further information regarding Quartz scheduling: