package com.pgf.mqspring; import java.io.IOException; import javax.jms.ConnectionFactory; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.jms.annotation.EnableJms; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.config.JmsListenerContainerFactory; import org.springframework.jms.core.JmsTemplate; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.view.RedirectView; import com.pgf.mqspring.model.ReplyRequestModel; import com.pgf.mqspring.model.TestModel; import com.pgf.mqspring.service.MqReceiveService; import com.pgf.mqspring.service.MqSendService; import com.pgf.mqspring.service.impl.MqReceiveServiceImpl; import com.pgf.mqspring.service.impl.MqSendServiceImpl; @SpringBootApplication @RestController @EnableJms @EnableCaching public class MqSpringApplication { static private ConfigurableApplicationContext context = null; static private JmsTemplate jmsTemplate = null; static private Logger logger = null; public static void main(String[] args) { logger = LogManager.getLogger(); context = SpringApplication.run(MqSpringApplication.class, args); jmsTemplate = context.getBean(JmsTemplate.class); //TODO:↓後でコメント解除する // 受信待ち時間のタイムアウトを60秒に設定 //jmsTemplate.setReceiveTimeout(60000); // メッセージの生存時間を60秒に設定 //jmsTemplate.setExplicitQosEnabled(true); //jmsTemplate.setTimeToLive(60000); //TODO:↓Apigeeの検証するときコメント解除する //requestAuthFilter.init(null); TelegramInfo.initTelegramInfo(); } @Bean JmsListenerContainerFactory listenerFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConcurrency("1-1"); // This provides all boot's default to this factory, including the message converter configurer.configure(factory, connectionFactory); // You could still override some of Boot's default if necessary. return factory; } @RequestMapping("/pgf/mq-rest/v1/apl/cda/sendRawData") RedirectView sendRawData(@RequestBody TestModel testModel) throws IOException, InterruptedException { MqSendService service = new MqSendServiceImpl(jmsTemplate); service.setQueue("QL.TEST.IN"); //service.setQueue("QL.POC05.TEST"); if (!"200".equals(service.sendRawData(testModel))) { return new RedirectView("/send-ng"); } Thread.sleep(360); String str = service.getMessageId(); logger.info("MessageID=" + str); return new RedirectView("/recvMessage?id=" + str); } @RequestMapping(value = "/pgf/mq-rest/v1/apl/cda/reply", consumes = "application/json", produces = "application/json") RedirectView replyRequest(@RequestBody(required = false) ReplyRequestModel request) throws InterruptedException { MqSendService service = new MqSendServiceImpl(jmsTemplate); service.setQueue("QL.TEST.IN"); String ret = service.sendMqMessage(request); if (!"200".equals(ret)) { return new RedirectView("/send-ng"); } Thread.sleep(360); String str = service.getMessageId(); logger.info("MessageID=" + str); return new RedirectView("/recvMessage?id=" + str); } @RequestMapping("/recvMessage") String recvMessage(@RequestParam(name = "id") String id) { MqReceiveService service = new MqReceiveServiceImpl(jmsTemplate); service.setQueue("QL.TEST.REPLY"); if (id.length() > 0) { String ret = service.receiveMessage(id); return ret; } return "500"; } @RequestMapping("send-ng") String sendNg() { return "SEND FAIL"; } }