首页 \ 问答 \ Tomcat无法与Artemis MQ通信(Tomcat failing to communicate with Artemis MQ)

Tomcat无法与Artemis MQ通信(Tomcat failing to communicate with 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

I wanted to schedule a message delay using JMS. For that I'm using JMS 2.0 with Artemis MQ and the message is scheduled successfully in compile time but when I deploy it in Tomcat and try to send the message with a delay it says:

java.lang.IllegalStateException: setDeliveryDelay requires JMS 2.0

I'm guessing that the Tomcat isn't able to communicate properly with the Artemis server I have setup. So I have two servers setup in my system: Tomcat and Artemis. Is it because Tomcat can't communicate with Artemis? If so, then why does my spring boot in-built Tomcat server detects Artemis but my standalone Tomcat doesn't?

My source code for the JMS message sender is:

@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);
    }
}

My pom.xml is:

 <?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>

My application.properties is:

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

原文:https://stackoverflow.com/questions/48655858
更新时间:2023-05-09 06:05

最满意答案

您可以使用Windows任务计划程序进行此类工作。 在这里查看Schtasks命令行选项(其中有很多)

例1:

计划在每个月的第一天运行的任务

以下命令安排MyApp程序在每个月的第一天运行。 因为值为1是/ mo(修饰符)参数和/ d(日)参数的默认值,所以这些参数将从命令中省略。

schtasks /create /tn "My App" /tr myapp.exe /sc monthly

例2:

安排第15天的任务

以下命令安排MyApp程序在每个月的15日(下午3:00(15:00))运行。 它使用/ d参数指定日期。 它还使用/ st参数指定开始时间。

schtasks /create /tn "My App" /tr myapp.exe /sc monthly /d 15 /st 15:00

You could use the Windows Task Scheduler for this kind of work. Look here for command line options of Schtasks (there's tons of them)

Example 1:

To schedule a task that runs on the first day of every month

The following command schedules the MyApp program to run on the first day of every month. Because a value of 1 is the default for both the /mo (modifier) parameter and the /d (day) parameter, these parameters are omitted from the command.

schtasks /create /tn "My App" /tr myapp.exe /sc monthly

Example 2:

To schedule a task for the 15th day

The following command schedules the MyApp program to run on 15th of every month at 3:00 P.M. (15:00). It uses the /d parameter to specify the date. It also uses the /st parameter to specify the start time.

schtasks /create /tn "My App" /tr myapp.exe /sc monthly /d 15 /st 15:00

相关问答

更多
  • 我设法说服老板使用Windows预定任务。 有一种方法可以使用计时器。 我在下面提供了代码。 这很快又很脏。 请注意,使用计划任务是实现此类任务的正确方法。 private Timer timer; public MyClass() { timer = new Timer(); timer.Elapsed += TimerElapsed; } private void TimerElapsed(object sender, Elap ...
  • 您可以使用Windows任务计划程序进行此类工作。 在这里查看Schtasks命令行选项(其中有很多) 例1: 计划在每个月的第一天运行的任务 以下命令安排MyApp程序在每个月的第一天运行。 因为值为1是/ mo(修饰符)参数和/ d(日)参数的默认值,所以这些参数将从命令中省略。 schtasks /create /tn "My App" /tr myapp.exe /sc monthly 例2: 安排第15天的任务 以下命令安排MyApp程序在每个月的15日(下午3:00(15:00))运行。 它使 ...
  • 尝试在执行管理任务之前禁用计时器,然后重新启用: tmrStore.Enabled = false; try{ // do stuff }finally{ tmrStore.Enabled = true; } 问题的原因可能是计时器处理程序的主体执行时间比Timer.Ticks值要长,因此您的计时器事件开始堆叠在彼此之上。 您可能还会考虑将此代码放在线程而不是计时器中,以便它独立于您的用户界面。 Right I've resolved the issue its because I had ...
  • 正如@spender所建议的,我删除了计时器并使用了Task.Delay(),它起作用: private async void btnOk_Click(object sender, EventArgs e) { this.close() // closes form to prevent further input; is this why timer failed? // Some codes Task task = Task.Run(() => PDF.Mer ...
  • 尽快停止计时器,一旦进入勾号: timer.Tick += (s, e) => { ((System.Windows.Forms.Timer)s).Stop(); //s is the Timer action(); }; Try stopping the timer as soon as it enters Tick: timer.Tick += (s, e) => { ((System.Windows.Forms.Timer)s).Stop(); //s is the Timer ...
  • 假设您正在使用System.Timers.Timer那么Timer事件通常在后台线程中引发,这意味着没有任何锁定,您的计时器事件方法可能会重叠。 一个简单的解决方案是将AutoReset设置为false ,而在您的计时器事件中重新启动它,例如: private bool terminating; public Service() { terminating = false; timer = new Timer(1000); timer.Elapsed += new Elapsed ...
  • 我担心您忘记将事件处理程序附加到Tick事件: private void Form1_Load(object sender, EventArgs e) { timer1.Tick += timer1_Tick_1; timer1.Interval = 2000; timer1.Enabled = true; timer1.Start(); } I'm afraid you forgot to attach your event handler to the Tick event: private void ...
  • 使用Timer Tick事件检查(将tick设置为合适的值),然后在tick事件中进行检查: DateTime Now = DateTime.Now; if(Now.Hours == DateTimeCallX.Hours && Now.Minutes == DateTimeCallX.Minutes && xHasRan == false) { x(); xHasRan = true; } DateTimeCallX是一个设置为20:00的DateTime对象。 xHasRan ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)