Guest User

Untitled

a guest
Apr 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. @Configuration
  2. public class JMSConfig {
  3. @Value("${spring.artemis.host}")
  4. private String artemisHost;
  5. @Value("${spring.artemis.port}")
  6. private String artemisPort;
  7. @Value("${spring.artemis.user}")
  8. private String artemisUser;
  9. @Value("${spring.artemis.password}")
  10. private String artemisPass;
  11. @Bean
  12. @Primary
  13. public CachingConnectionFactory cachingConnectionFactory() {
  14. StringBuilder artemisURL = new StringBuilder();
  15. artemisURL.append("tcp://").append(artemisHost).append(":").append(artemisPort).append("?jms.useAsyncSend=true");
  16. ActiveMQConnectionFactory artemiConnFactory = new ActiveMQConnectionFactory(artemisURL.toString());
  17. artemiConnFactory.setUser(artemisUser);
  18. artemiConnFactory.setPassword(artemisPass);
  19. artemiConnFactory.setConsumerWindowSize(0);
  20. CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(artemiConnFactory);
  21. cachingConnectionFactory.setSessionCacheSize(20);
  22. return cachingConnectionFactory;
  23. }
  24. @Bean
  25. @Primary
  26. public JmsTemplate jmsTemplate(@Qualifier("cachingConnectionFactory") CachingConnectionFactory connectionFactory) {
  27. JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
  28. return jmsTemplate;
  29. }
  30. }
  31.  
  32. @Aspect
  33. @Component
  34. public class MyGlobalExceptionHandler {
  35.  
  36. @Autowired
  37. private JmsTemplate jmsTemplate;
  38. @Value("${environment}.${errlog.log.queue}")
  39. private String errorLogQueue;
  40. @Value("${spring.application.name}")
  41. private String applicationName;
  42.  
  43. @AfterThrowing(
  44. pointcut = "within(com.my.service..*..*) && (@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.jms.annotation.JmsListener))",
  45. throwing = "myException")
  46. public Response<Void> handleException(MyException myException) {
  47. ErrLogRequest logRequest = LoggerBuilder.build(myException, applicationName);
  48. jmsTemplate.send(errorLogQueue, session -> session.createTextMessage(logRequest.toString()));
  49. return Response.<Void>builder().status(myException.errorCode).build();
  50. }
  51. }
Add Comment
Please, Sign In to add comment