예제 코드
예제 코드는 일부 수정된 것입니다. 작성 시점에서는 Spring Boot 3.3.0(Spring Framework 6.1.8)을 사용하고 있습니다.
완전/pom.xml
ActiveMQ 임베디드 브로커로 전환
<dependency> <groupid>org.springframework.boot</groupid> <!--<artifactId>spring-boot-starter-artemis</artifactId>--> <artifactid>spring-boot-starter-activemq</artifactid> </dependency> <dependency> <groupid>org.apache.activemq</groupid> <!--<artifactId>artemis-jakarta-server</artifactId>--> <artifactid>activemq-broker</artifactid> <scope>runtime</scope> </dependency> <!-- ... -->
완전/src/main/resources/application.properties
디버그 로깅을 켜고 내장된 브로커 URL을 설정하세요
#spring.artemis.mode=embedded debug=true spring.activemq.broker-url=vm://localhost?broker.persistent=false
완전/src/main/java/hello/Application.java
직접 빌드하는 대신 Spring Boot에서 생성한 JmsListenerContainerFactory Bean을 사용하세요
@SpringBootApplication @EnableJms public class Application { /*@Bean public JmsListenerContainerFactory> myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); // This provides all auto-configured defaults to this factory, including the message converter configurer.configure(factory, connectionFactory); // You could still override some settings if necessary. return factory; }*/ //... }
완전/src/main/java/hello/Receiver.java
기본값 지정 JmsListenerContainerFactory
@Component public class Receiver { //@JmsListener(destination = "mailbox", containerFactory = "myFactory") @JmsListener(destination = "mailbox") public void receiveMessage(Email email) { System.out.println("Received "); } }
Spring Boot 자동 구성 로그
JMS 관련 구성만 표시됩니다.
ActiveMQAutoConfiguration matched: - @ConditionalOnClass found required classes 'jakarta.jms.ConnectionFactory', 'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition) - @ConditionalOnMissingBean (types: jakarta.jms.ConnectionFactory; SearchStrategy: all) did not find any beans (OnBeanCondition) ActiveMQAutoConfiguration#activemqConnectionDetails matched: - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionDetails; SearchStrategy: all) did not find any beans (OnBeanCondition) ActiveMQConnectionFactoryConfiguration matched: - @ConditionalOnMissingBean (types: jakarta.jms.ConnectionFactory; SearchStrategy: all) did not find any beans (OnBeanCondition) ActiveMQConnectionFactoryConfiguration.SimpleConnectionFactoryConfiguration matched: - @ConditionalOnProperty (spring.activemq.pool.enabled=false) matched (OnPropertyCondition) ActiveMQConnectionFactoryConfiguration.SimpleConnectionFactoryConfiguration.CachingConnectionFactoryConfiguration matched: - @ConditionalOnClass found required class 'org.springframework.jms.connection.CachingConnectionFactory' (OnClassCondition) - @ConditionalOnProperty (spring.jms.cache.enabled=true) matched (OnPropertyCondition) JmsAnnotationDrivenConfiguration matched: - @ConditionalOnClass found required class 'org.springframework.jms.annotation.EnableJms' (OnClassCondition) JmsAnnotationDrivenConfiguration#jmsListenerContainerFactory matched: - @ConditionalOnSingleCandidate (types: jakarta.jms.ConnectionFactory; SearchStrategy: all) found a single bean 'jmsConnectionFactory'; @ConditionalOnMissingBean (names: jmsListenerContainerFactory; SearchStrategy: all) did not find any beans (OnBeanCondition) JmsAnnotationDrivenConfiguration#jmsListenerContainerFactoryConfigurer matched: - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer; SearchStrategy: all) did not find any beans (OnBeanCondition) JmsAutoConfiguration matched: - @ConditionalOnClass found required classes 'jakarta.jms.Message', 'org.springframework.jms.core.JmsTemplate' (OnClassCondition) - @ConditionalOnBean (types: jakarta.jms.ConnectionFactory; SearchStrategy: all) found bean 'jmsConnectionFactory' (OnBeanCondition) JmsAutoConfiguration.JmsTemplateConfiguration#jmsTemplate matched: - @ConditionalOnSingleCandidate (types: jakarta.jms.ConnectionFactory; SearchStrategy: all) found a single bean 'jmsConnectionFactory'; @ConditionalOnMissingBean (types: org.springframework.jms.core.JmsOperations; SearchStrategy: all) did not find any beans (OnBeanCondition) JmsAutoConfiguration.MessagingTemplateConfiguration matched: - @ConditionalOnClass found required class 'org.springframework.jms.core.JmsMessagingTemplate' (OnClassCondition) JmsAutoConfiguration.MessagingTemplateConfiguration#jmsMessagingTemplate matched: - @ConditionalOnSingleCandidate (types: org.springframework.jms.core.JmsTemplate; SearchStrategy: all) found a single bean 'jmsTemplate'; @ConditionalOnMissingBean (types: org.springframework.jms.core.JmsMessageOperations; SearchStrategy: all) did not find any beans (OnBeanCondition)
관련 인터페이스
Interface | Function |
---|---|
org.springframework.jms.support.destination.DestinationResolver | lookup jakarta.jms.Destination instance by String name |
org.springframework.transaction.jta.JtaTransactionManager | control transaction by JTA |
org.springframework.jms.support.converter.MessageConverter | serialize/deserialize DTO instance |
jakarta.jms.ExceptionListener | processor when jakarta.jms.JMSException throws. One implementation is SingleConnectionFactory, connection managed by that class will be restarted once exception is catched |
io.micrometer.observation.ObservationRegistry | for statistics |
커넥션팩토리 소개
ActiveMQ 구현체는 org.apache.activemq.ActiveMQConnectionFactory이지만 Spring Framework에서는 이를 직접 사용하지 않습니다. 클래스는 다음을 위해 org.springframework.jms.connection.CachingConnectionFactory로 래핑됩니다
- 한 개의 연결만 생성되며 재사용됩니다
- 캐시 MessageProducer 및 MessageConsumer(이 예에서는 MessageProducer만 캐시됩니다.)
발행자
org.springframework.jms.core.JmsTemplate을 통해 메시지 보내기
<dependency> <groupid>org.springframework.boot</groupid> <!--<artifactId>spring-boot-starter-artemis</artifactId>--> <artifactid>spring-boot-starter-activemq</artifactid> </dependency> <dependency> <groupid>org.apache.activemq</groupid> <!--<artifactId>artemis-jakarta-server</artifactId>--> <artifactid>activemq-broker</artifactid> <scope>runtime</scope> </dependency> <!-- ... -->
JmsTemplate 빈은 org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration.JmsTemplateConfiguration#jmsTemplate에 의해 빌드됩니다. DTO를 역직렬화하려면 MessageConverter Bean이 필요합니다.
DestinationResolver는 org.springframework.jms.support.destination.DynamicDestinationResolver이고, 클래스는 jakarta.jms.Destination 인스턴스를 호출하여 가져옵니다. 🎜>jakarta.jms.Session#createTopic 또는 jakarta.jms.Session#createQueue.
구독자
org.springframework.jms.annotation.JmsListener 주석
attribute | Function |
---|---|
id | prefix of thread name which run listener |
containerFactory | bean name of JmsListenerContainerFactory instance |
destination | the destination name for this listener |
subscription | the name of the durable subscription, if any |
selector | an optional message selector for this listener |
concurrency | number of thread running listener |
org.springframework.jms.listener.DefaultMessageListenerContainer 클래스
JMS 사양에서는 비동기 메시지 처리가 지원되며 리스너는 JMS 공급자의 스레드에서 실행됩니다.
<dependency> <groupid>org.springframework.boot</groupid> <!--<artifactId>spring-boot-starter-artemis</artifactId>--> <artifactid>spring-boot-starter-activemq</artifactid> </dependency> <dependency> <groupid>org.apache.activemq</groupid> <!--<artifactId>artemis-jakarta-server</artifactId>--> <artifactid>activemq-broker</artifactid> <scope>runtime</scope> </dependency> <!-- ... -->
그러나 Spring Framework에서는 비동기식 접근 방식을 사용하지 않고 동기식 API(폴링)를 사용합니다. 실제 코드는 org.springframework.jms.support.destination.JmsDestinationAccessor#receiveFromConsumer에 있습니다.
#spring.artemis.mode=embedded debug=true spring.activemq.broker-url=vm://localhost?broker.persistent=false
org.springframework.jms.listener.DefaultMessageListenerContainer.AsyncMessageListenerInvoker 클래스는 주기적으로 폴링 작업을 수행하기 위한 클래스입니다. 이는 org.springframework.core.task.SimpleAsyncTaskExecutor에 예약되어 있습니다.
하나의 @JmsListener 주석이 달린 함수에 대해 하나의 DefaultMessageListenerContainer 인스턴스가 생성됩니다. 이는 org.springframework.jms.config.DefaultJmsListenerContainerFactory에서 생성됩니다.
물론 MessageConverter와 ExceptionListener 인스턴스가 필요합니다.
위 내용은 Spring Boot가 JMS를 지원하는 방법에 대한 간략한 살펴보기의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

이 기사는 2025 년에 상위 4 개의 JavaScript 프레임 워크 (React, Angular, Vue, Svelte)를 분석하여 성능, 확장 성 및 향후 전망을 비교합니다. 강력한 공동체와 생태계로 인해 모두 지배적이지만 상대적으로 대중적으로

이 기사는 카페인 및 구아바 캐시를 사용하여 자바에서 다단계 캐싱을 구현하여 응용 프로그램 성능을 향상시키는 것에 대해 설명합니다. 구성 및 퇴거 정책 관리 Best Pra와 함께 설정, 통합 및 성능 이점을 다룹니다.

Node.js 20은 V8 엔진 개선, 특히 더 빠른 쓰레기 수집 및 I/O를 통해 성능을 크게 향상시킵니다. 새로운 기능에는 더 나은 webAssembly 지원 및 정제 디버깅 도구, 개발자 생산성 및 응용 속도 향상이 포함됩니다.

Java의 클래스 로딩에는 부트 스트랩, 확장 및 응용 프로그램 클래스 로더가있는 계층 적 시스템을 사용하여 클래스로드, 링크 및 초기화 클래스가 포함됩니다. 학부모 위임 모델은 핵심 클래스가 먼저로드되어 사용자 정의 클래스 LOA에 영향을 미치도록합니다.

대규모 분석 데이터 세트를위한 오픈 테이블 형식 인 Iceberg는 데이터 호수 성능 및 확장 성을 향상시킵니다. 내부 메타 데이터 관리를 통한 Parquet/Orc의 한계를 해결하여 효율적인 스키마 진화, 시간 여행, 동시 W를 가능하게합니다.

이 기사는 원격 코드 실행을 허용하는 중요한 결함 인 Snakeyaml의 CVE-2022-1471 취약점을 다룹니다. Snakeyaml 1.33 이상으로 Spring Boot 응용 프로그램을 업그레이드하는 방법에 대해 자세히 설명합니다.

이 기사는 Lambda 표현식, 스트림 API, 메소드 참조 및 선택 사항을 사용하여 기능 프로그래밍을 Java에 통합합니다. 간결함과 불변성을 통한 개선 된 코드 가독성 및 유지 관리 가능성과 같은 이점을 강조합니다.

이 기사에서는 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 및 Gradle을 사용하여 접근 방식과 최적화 전략을 비교합니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Dreamweaver Mac版
시각적 웹 개발 도구
