Download Artemis2.13.0, create a multicast address test in advance, then create a multicast queue 123 on this address, use the console to send 1 message to the 123 queue
Use IDEA to create a springboot project, the pom file imports the following dependencies
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-artemis</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>5.2.5.RELEASE</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>artemis-jms-client</artifactId> <version>2.13.0</version> <scope>compile</scope> </dependency>
pplication.properties add configuration
spring.artemis.mode=native spring.artemis.host=localhost spring.artemis.port=61616 spring.artemis.user=test spring.artemis.password=123456 spring.jms.pub-sub-domain=true
Create consumer to receive messages pre-created in queue 123
import org.springframework.jms.annotation.JmsListener; import org.springframework.stereotype.Component; @Component public class Consumer{ @JmsListener(destination="test::123") public void consumerMessage(String text){ System.out.println("从queue队列收到的回复信息为:"+text); } }
I can't receive the message, using 2.13.0 artemis-jms-client the following error message appears
Setup of JMS message listener invoker failed for destination 'test::123' - trying to recover. Cause: AMQ229019: Queue 123 already exists on address test
Use IDEA to directly create a new springboot project without any modification.
Artemis creates a server and does not modify the broker file.
1 Answers
It's fairly abnormal to pre-create a multicast queue for a JMS use-case. Typically you'd simply use the name of the address as the name of the JMS topic in your application and then the broker would automatically create a queue on the address to represent the application's JMS subscription and then the application would receive any messages sent to that address. The semantics for mapping JMS concepts to the core broker implementation is discussed further in the documentation.
However, if your use-case compels you to pre-create the multicast queue then you can access that queue by using the fully qualified queue name (i.e. FQQN) which follows the form of <address>::<queue>
. So in your case you'd use test::123
, e.g.:
@JmsListener(destination = "test::123")
public void receiveQueueMsg(String msg) {
System.out.println("收到的消息为:" + msg);
}
FQQN syntax and functionality is discussed further in the documentation.
For what it's worth, I modified the spring-boot-integration
example that ships with ActiveMQ Artemis to use the normal JMS client (i.e. not the AMQP JMS client) and to use FQQN with a multicast queue and everything worked as expected.