You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:

Spring Boot ActiveMQ Consumer Setup

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:54:11