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
最满意答案
您可以使用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
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
我设法说服老板使用Windows预定任务。 有一种方法可以使用计时器。 我在下面提供了代码。 这很快又很脏。 请注意,使用计划任务是实现此类任务的正确方法。 private Timer timer; public MyClass() { timer = new Timer(); timer.Elapsed += TimerElapsed; } private void TimerElapsed(object sender, Elap ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以使用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))运行。 它使 ...
-
C#计时器问题(C# timer issue)[2022-08-10]
尝试在执行管理任务之前禁用计时器,然后重新启用: tmrStore.Enabled = false; try{ // do stuff }finally{ tmrStore.Enabled = true; } 问题的原因可能是计时器处理程序的主体执行时间比Timer.Ticks值要长,因此您的计时器事件开始堆叠在彼此之上。 您可能还会考虑将此代码放在线程而不是计时器中,以便它独立于您的用户界面。 Right I've resolved the issue its because I had ... -
C#计时器无法启动?(C# timer not starting?)[2022-03-24]
正如@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 Tasktask = 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 ...
-
C#计时器无法正常工作(C# timer is not working)[2022-03-01]
我担心您忘记将事件处理程序附加到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 ... -
计时器类和C#(Timer class and C#)[2022-08-10]
使用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 ...