我想创建与 EmbeddedActiveMQBroker 的连接,并且还想在 Message 中设置 String 属性,以便侦听器可以从 Message 中提取这些 String 属性。我想使用 Message.class 来发送和接收消息。
我的目标是在此消息集 String 属性中生成消息并向输入队列生成消息。下一部分是我的侦听器应该能够从此输入队列侦听并能够从 Message 中提取这些 String 属性。
import org.apache.activemq.junit.EmbeddedActiveMQBroker;
import org.junit.ClassRule;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class JmsMessageListeningAndSendingTest extends IntegrationTestBase {
@ClassRule
public static EmbeddedActiveMQBroker embeddedBroker = new EmbeddedActiveMQBroker();
}
Error Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryFactory.doCreateConnectionFactory(ActiveMQConnectionFactoryFactory.java:67)
The following method did not exist:
'void org.apache.activemq.ActiveMQConnectionFactory.setNonBlockingRedelivery(boolean)'
The calling method's class, org.springframework.boot.autoconfigure.jms.activemq.ActiveMQConnectionFactoryFactory, was loaded from the following location:
Application.yml
activemq:
broker-url: tcp://localhost:61616
close-timeout: 15
packages:
trusted: com.broker.activemq.entities,java.lang
password: admin
user: admin
in-memory: true
pool:
enabled: false
build.gradle
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
testImplementation 'org.mockito:mockito-junit-jupiter:4.8.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner:4.1.0'
testImplementation 'org.mockito:mockito-core:5.8.0'
testImplementation 'org.testcontainers:testcontainers:1.19.3'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.apache.activemq:activemq-broker:6.0.1'
implementation 'org.apache.activemq:activemq-all:5.4.2'
testImplementation 'org.apache.activemq.tooling:activemq-junit:6.0.1'
testImplementation 'org.testcontainers:junit-jupiter:1.16.3'
正如评论中指出的,这一定是SB3(jakarta)和ActiveMQ嵌入式版本的依赖问题。
从 v6 开始,ActiveMQ 现已兼容 jakarta。
您应该使用以下版本的 6.0.1,并尝试看看它是否可以解决您的问题。
梅文:
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>activemq-junit</artifactId>
<version>6.0.1</version>
或者 gradle :
org.apache.activemq.tooling:activemq-junit:6.0.1
如果此依赖项本身没有修复,您仍然可以按照该指南从java创建EmbeddedServer。