美文网首页
Springboot ActiveMQ Producer

Springboot ActiveMQ Producer

作者: 曹振华 | 来源:发表于2017-04-25 21:02 被阅读133次
    @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));
    }
    }

    相关文章

      网友评论

          本文标题:Springboot ActiveMQ Producer

          本文链接:https://www.haomeiwen.com/subject/jmlbzttx.html