I am using Spring Integration in a Spring MVC controller context, and I need implementing Request/Reply style message interaction.
The code is as follows:
To recieve the correlated reply message, I created a temporary message channel and register it with the MessageBus, is that the best practice to implement Request/Reply style interaction in Spring Integration or Is there other alternative method?Code:private void processWithTempReplyChannel(HttpServletRequest request, ModelMap model) { ApplicationContext applicationContext = (ApplicationContext) getApplicationContext(); //context.start(); ATransaction aTransaction = new ATransactionImpl(); acordTransaction.setRequestMessage(request.getParameter("requestMessage")); ChannelRegistry channelRegistry = (ChannelRegistry) applicationContext.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME); MessageChannel returnChannel = new SimpleChannel(); String tmpReplyChannel = "aTemp" + nextId++; channelRegistry.registerChannel(tmpReplyChannel, returnChannel); GenericMessage requestMessage = new GenericMessage<ATransaction>(aTransaction); requestMessage.getHeader().setReturnAddress(outputChannel); requests.send(requestMessage); Message replyMessage = returnChannel.receive(5000); if (replyMessage == null) { saveMessage(request, "processing timed out"); } else { ATransaction responseMessage = (ATransaction) replyMessage.getPayload(); System.out.println(responseMessage); } channelRegistry.unregisterChannel(tmpReplyChannel); }


Reply With Quote