Spring Boot整合ActiveMQ消费者开发求助(新手入门)
Hey there! Since you're new to Spring Boot + ActiveMQ, let's get your code properly formatted and add some quick tips to help you avoid common pitfalls:
1. Application Configuration (application.properties)
First, here's your config in a proper code block:
spring.activemq.broker-url=tcp://localhost:8161 spring.activemq.user=admin spring.activemq.password=admin
Quick heads-up: ActiveMQ's default TCP broker port is 61616 (8161 is the web console port). You'll want to update spring.activemq.broker-url to tcp://localhost:61616 otherwise your app won't be able to connect to the broker.
2. Main Application Class (SampleActiveMQApplication.java)
Here's your startup class with a small fix (the class name in SpringApplication.run() didn't match the current class):
@SpringBootApplication @EnableJms public class SampleActiveMQApplication { public static void main(String[] args) { // Fixed the class name to match the current class SpringApplication.run(SampleActiveMQApplication.class, args); } }
3. Consumer Class (Consumer.java)
It looks like your code got truncated at @JmsLi...—I've filled in the common implementation for a JMS listener:
@Component public class Consumer { // Listen for messages on the specified queue @JmsListener(destination = "my-activemq-queue") public void receiveMessage(String message) { System.out.println("Received message from queue: " + message); // Add your business logic to process the message here } }
Don't forget to replace my-activemq-queue with the actual name of the queue you want to listen to!
内容的提问来源于stack exchange,提问作者Saurabh Jhunjhunwala

