@Component
public class Producer {
private final JmsTemplate jmsQueueTemplate;
private final JmsTemplate jmsTopicTemplate;
@Value("${wechat.sendmessage.topic}")
private String topic;
@Value("${wechat.sendmessage.queue}")
private String queue;
@Autowired
public AMQProducer(@Qualifier("jmsTopicTemplate") JmsTemplate jmsTopicTemplate, @Qualifier("jmsQueueTemplate") JmsTemplate jmsQueueTemplate) {
this.jmsQueueTemplate = jmsQueueTemplate;
this.jmsTopicTemplate = jmsTopicTemplate;
}
/**
* cron: new ScheduleMessagePostProcessor("40 22 * * *")
* delay: new ScheduleMessagePostProcessor(30 * 1000)
* @param postScheduleMessage 定时任务内容
*/
public void send(PostScheduleMessage postScheduleMessage) {
jmsQueueTemplate.setDefaultDestinationName(queue);
Object message = postScheduleMessage.toString();
jmsQueueTemplate.convertAndSend(message, new ScheduleMessagePostProcessor(postScheduleMessage));
}
}
网友评论