Transaction management for Rest API endpoint With JMS transactions

13 Views Asked by At

I have a Spring boot applicaiton which have Rest controller class and in turn calls an service bean object which publishes JMS message to Active MQ.

Here, the JMS tranaction still persisting the message to Queue even after Rest api endpoint is timedout. I would like to prevent/rollback the JMS transaction persistance to queue if my Rest api endpoint is timedout.

Below is the java program.

@RestController
@RequestMapping("/router")
public class AppController {
    
    @Autowired
    private RestToAmqInterface restToAmqConnector;
    
    @PostMapping("/message")
    public void routeMessage(@RequestBody Map<String, String> jsonString) {
        restToAmqConnector.processMessage(jsonString);
    }

}
@Service
public class RestToAmqConnector implements RestToAmqInterface{  

    @Autowired
    private MessageChannel outChannel;
    
    @Override
    public void processMessage(Map<String, String> messageMap) {
        try {
            ......
            outChannel.send(message);
            logger.info("Message published to Queue");
        } catch (Exception ex) {
            logger.error("Error occured on sending message to Queue: {}", ex);
        }
    }
}
@Configuration
public class ComponentConfig {

        @Bean
    public IntegrationFlow outResMessageAdapter() {
        return IntegrationFlow.from(this.outChannel()).handle(Jms.outboundAdapter(this.connectionFactoryAMQ())
                .destinationExpression("headers.".concat(ConnectorConstants.SOURCE_QUEUE))).get();
    }

}

I would like to prevent/rollback the JMS transaction persistance to queue if my Rest api endpoint is timedout.

0

There are 0 best solutions below