【发布时间】:2019-02-25 16:30:21
【问题描述】:
我正在通过以下方式向队列发送消息:
我想安排重复我的消息。我的意思是,无论我在控制器中的这条线jsmClient.send(identifier);(如下所示)发送什么消息,
我想继续发送,比如说 10 或 100 次(取决于我设置的计时器)。我的消费者(未在下面显示)将继续使用相同的消息,直到我要求它停止。例如,即使
我的生产者将发送消息 10 或 100 次,如果我想在第 5 次(如果生产者发送消息 10 次)或第 50 次(如果生产者发送消息 100 次)停止接收消息,
我应该能够做到这一点。
由于我使用的是 JMS 2 和 ActiveMQ(版本 5.15.8),我无法弄清楚以下内容:
Delay and Schedule Message Delivery 文档在以下部分中讨论了AMQ_SCHEDULED_REPEAT:
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("test msg");
long delay = 30 * 1000;
long period = 10 * 1000;
int repeat = 9;
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, period);
message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, repeat);
producer.send(message);
如果我理解正确,上面的代码考虑的不是 JMS 2 而是 JMS 1.1?我想知道我需要在下面的代码中进行哪些更改,以便我可以执行类似message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, repeat); 的操作。我在the Spring documentation 中找不到很多关于计划重复的有用信息。
我的 JmsProducer 类:
@Component
public class JmsProducer {
@Autowired
JmsTemplate jmsTemplate;
@Value("${jms.queue.destination}")
String destinationQueue;
public void send(String msg){
jmsTemplate.convertAndSend(destinationQueue, msg);
}
}
JmsClient 接口:
public interface JmsClient {
public void send(String msg);
}
JmsClientImpl 类:
@Service
public class JmsClientImpl implements JmsClient{
@Autowired
JmsProducer jmsProducer;
@Override
public void send(String msg) {
jmsProducer.send(msg);
}
}
在我的 REST 控制器中,我正在发送这样的消息:
try {
DataRetrieverDao dataRetrieverDao = (DataRetrieverDao) context.getBean("dataRetrieverDao");
String identifier=dataRetrieverDao.sendDownloadInfo(user_id);
logger.info("VALUE OF STRING: "+identifier);
jsmClient.send(identifier);
}
基于我的研究:
在this stackoverflow thread,activemq 包不支持JMS 2.0,所以我应该改用artemis 吗?但是,我从上面的 jmsTemplate 方面提出的问题仍然在我的脑海中。请告诉我在这种情况下最好的行动方案是什么。谢谢
【问题讨论】:
标签: java jms activemq spring-jms activemq-artemis