https://docs.spring.io/spring-framework/docs/3.0.x/spring-framework-reference/html/jms.html
Configuration 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 @Configuration @EnableJms public class JmsConfig { @Bean public MessageConverter jacksonJmsMessageConverter () { MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); converter.setTargetType(MessageType.TEXT); converter.setTypeIdPropertyName("_type" ); return converter; } @Bean public Queue queue () { return new ActiveMQQueue("amq" ); } }
Producer 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @Data @AllArgsConstructor @NoArgsConstructor public class Email { private String to; private String body; } @Component @RequiredArgsConstructor public class MsgSender { private final JmsMessagingTemplate jmsMessagingTemplate; private final Queue queue; public void send () { jmsMessagingTemplate.convertAndSend(queue, new Email("info@example.com" , "Hello" )); } }
Consumer 1 2 3 4 5 6 7 8 9 @Component @Slf4j public class MsgReceiver { @JmsListener(destination = "amq") public void receive (Email email) { log.info("Received < {} >" , email); } }
Title: JMS
Author: mjd507
Date: 2022-04-17
Last Update: 2024-01-27
Blog Link: https://mjd507.github.io/2022/04/17/JMS/
Copyright Declaration: This station is mainly used to sort out incomprehensible knowledge. I have not fully mastered most of the content. Please refer carefully.