Last active
May 23, 2018 11:25
-
-
Save bdarfler/2485f3d5e8c169e8154d857596d8aa81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class Requestor { | |
private static final class CorrelationIdPostProcessor implements MessagePostProcessor { | |
private final String correlationId; | |
public CorrelationIdPostProcessor( final String correlationId ) { | |
this.correlationId = correlationId; | |
} | |
@Override | |
public Message postProcessMessage( final Message msg ) throws JMSException { | |
msg.setJMSCorrelationID( correlationId ); | |
return msg; | |
} | |
} | |
private final JmsTemplate jmsTemplate; | |
@Autowired | |
public RequestGateway( JmsTemplate jmsTemplate ) { | |
this.jmsTemplate = jmsTemplate; | |
} | |
public String request( final String request, String queue ) throws IOException { | |
final String correlationId = UUID.randomUUID().toString(); | |
jmsTemplate.convertAndSend( queue+”.request”, request, new CorrelationIdPostProcessor( correlationId ) ); | |
return (String) jmsTemplate.receiveSelectedAndConvert( queue+”.response”, “JMSCorrelationID=’” + correlationId + “‘“ ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment