I am sending message to the queue in the following manner:
I want to schedule repeat my message. I mean, whatever message my this line jsmClient.send(identifier);
in the controller(shown below) is sending,
I want to keep on sending, say for 10 or 100 times (depending upon the timer I set). My consumer(not shown below) will keep on consuming the same message until I ask it to stop. For example, even though
my producer is going to send the message 10 or 100 times, if I want to stop receiving the message at 5th time(in case of producer sending message 10 times) or 50th time (in case of producer sending message 100 times),
I should be able to do that.
Since I am using JMS 2 and ActiveMQ (version 5.15.8), I am not able to figure out the following:
The Delay and Schedule Message Delivery documentation talks about the AMQ_SCHEDULED_REPEAT
in the following section:
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);
If I understood correctly, the above code isn't considering JMS 2 but JMS 1.1? I am wondering what changes I need to make in my code below so that I could do something like this message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, repeat);
. I couldn't find much useful info regarding schedule repeat in the Spring documentation.
My JmsProducer class :
@Component
public class JmsProducer {
@Autowired
JmsTemplate jmsTemplate;
@Value("${jms.queue.destination}")
String destinationQueue;
public void send(String msg){
jmsTemplate.convertAndSend(destinationQueue, msg);
}
}
JmsClient Interface:
public interface JmsClient {
public void send(String msg);
}
JmsClientImpl class :
@Service
public class JmsClientImpl implements JmsClient{
@Autowired
JmsProducer jmsProducer;
@Override
public void send(String msg) {
jmsProducer.send(msg);
}
}
In my REST Controller, I am sending a message like this :
try {
DataRetrieverDao dataRetrieverDao = (DataRetrieverDao) context.getBean("dataRetrieverDao");
String identifier=dataRetrieverDao.sendDownloadInfo(user_id);
logger.info("VALUE OF STRING: "+identifier);
jsmClient.send(identifier);
}
Based on my Research:
In this stackoverflow thread, JMS 2.0 is not supported in the activemq package, so should I switch to artemis instead? But then, the questions I asked from jmsTemplate side above are still in my mind. Please advise what's the best course of action in this situation for me. Thanks