Tomcat未能与Artemis MQ进行交流



我想使用JMS安排消息延迟。为此,我正在使用Artemis MQ使用JMS 2.0,并且该消息已在编译时间成功安排,但是当我在Tomcat中部署并尝试以延迟发送消息时,它说:

java.lang.illegalstateException:setDeliveryDelay需要JMS 2.0

我猜想Tomcat无法与我设置的Artemis服务器进行正确的通信。因此,我的系统中有两个服务器设置:Tomcat和Artemis。是因为Tomcat无法与Artemis沟通吗?如果是这样,那么为什么我的春季启动在构建的tomcat服务器会检测到Artemis,但我的独立tomcat却没有?

我的JMS消息发件人的源代码是:

@Service
public class TransferServiceImpl implements TransferService {
    @Autowired
    private JmsTemplate jmsTemplate;
    @Override
    public void transfertoJMS(Transaction transaction) {
        System.out.println("Sending a transaction.");
        jmsTemplate.setDeliveryDelay(20000);
        jmsTemplate.convertAndSend(destinationQueue, transaction);
    }
}

我的pom.xml是:

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stargate.transferfund</groupId>
<artifactId>TransferFund</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>TransferFund</name>
<description>Demo project for Spring Boot</description>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <startClass>org.springframework.boot.SpringApplication</startClass>
    <maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- for test case, in memory db -->
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- marked the embedded servlet container as provided -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- JMS related dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-artemis</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>artemis-junit</artifactId>
        <version>1.5.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>
    <!-- http://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar -->
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

我的application.properties是:

server.port=${port:8085}
# database config
spring.datasource.url=jdbc:mysql://localhost:3306/ach_stargate
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
# jms config
jms.queue.destination=TransactionQueue
spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=61616
spring.artemis.user=admin
spring.artemis.password=admin

您与两个冲突的依赖关系发生了冲突。以下依赖性是ActiveMQ 5.x(!(:

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-broker</artifactId>
</dependency>

Spring可能正在从该依赖项中找到JMS 1.0规格,该依赖关系覆盖了您的classPath上的JMS 2.0规格,并在Spring寻找启动ConnectionFactory时使用必要的JMS接口时给您java.lang.IllegalStateException

如果您想要一个嵌入式经纪人,则spring-boot-starter-artemis已经包含它,因此您应该能够删除activemq-broker依赖性而不会出现问题。

相关内容

  • 没有找到相关文章

最新更新