Example.
We have a class that implements QueueService based on JmsTemplate (Spring)
Method sendMessage sends object to jms queue for future handle by message listeners
The problem is that queue injection should only be happens in case of successful transaction.
import org.springframework.jms.core.JmsTemplate; import com.company.annotations.MessageQueue; import com.company.jms.domain.QueueRequestHolder; import com.company.jms.service.QueueService; public class QueueServiceImpl implements QueueService { private final JmsTemplate jmsTemplate; public QueueServiceImpl(final JmsTemplate template) { jmsTemplate = template; } @MessageQueue() public QueueRequestHolder sendMessage(final Object objectToSend) { return new QueueRequestHolder(jmsTemplate, objectToSend); } public void sendMessageDirect(final Object objectToSend) { jmsTemplate.convertAndSend(objectToSend); } }
Recent