Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- public class JMSConfig {
- @Value("${spring.artemis.host}")
- private String artemisHost;
- @Value("${spring.artemis.port}")
- private String artemisPort;
- @Value("${spring.artemis.user}")
- private String artemisUser;
- @Value("${spring.artemis.password}")
- private String artemisPass;
- @Bean
- @Primary
- public CachingConnectionFactory cachingConnectionFactory() {
- StringBuilder artemisURL = new StringBuilder();
- artemisURL.append("tcp://").append(artemisHost).append(":").append(artemisPort).append("?jms.useAsyncSend=true");
- ActiveMQConnectionFactory artemiConnFactory = new ActiveMQConnectionFactory(artemisURL.toString());
- artemiConnFactory.setUser(artemisUser);
- artemiConnFactory.setPassword(artemisPass);
- artemiConnFactory.setConsumerWindowSize(0);
- CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(artemiConnFactory);
- cachingConnectionFactory.setSessionCacheSize(20);
- return cachingConnectionFactory;
- }
- @Bean
- @Primary
- public JmsTemplate jmsTemplate(@Qualifier("cachingConnectionFactory") CachingConnectionFactory connectionFactory) {
- JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
- return jmsTemplate;
- }
- }
- @Aspect
- @Component
- public class MyGlobalExceptionHandler {
- @Autowired
- private JmsTemplate jmsTemplate;
- @Value("${environment}.${errlog.log.queue}")
- private String errorLogQueue;
- @Value("${spring.application.name}")
- private String applicationName;
- @AfterThrowing(
- pointcut = "within(com.my.service..*..*) && (@annotation(org.springframework.web.bind.annotation.RequestMapping) || @annotation(org.springframework.jms.annotation.JmsListener))",
- throwing = "myException")
- public Response<Void> handleException(MyException myException) {
- ErrLogRequest logRequest = LoggerBuilder.build(myException, applicationName);
- jmsTemplate.send(errorLogQueue, session -> session.createTextMessage(logRequest.toString()));
- return Response.<Void>builder().status(myException.errorCode).build();
- }
- }
Add Comment
Please, Sign In to add comment