How to send email using activemq

Achaius

I am new to this activemq, I want to send an email for every hour using activemq data. How to configure this scheduling process in activemq? Is there any tutorial for this action?

Gabriel Ruiu

This is a pretty generic question, but I can give you some outlining hints regarding the scheduling using Spring:

  1. 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.

  2. 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
    }
    

    }

  3. 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>
  1. 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>
  1. 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:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related