SpringBoot整合ActiveMQ

  • Post author:
  • Post category:其他


1.加入依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.4</version>
</dependency>

2.增加配置类

package com.example.mq.config.properties;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "spring.activemq")
@Data
public class ActiveMqConfigProperties {
    @Value("user")
    private String user;
    @Value("password")
    private String password;
    @Value("broker-url")
    private String brokerUrl;
}

3.配置MQ连接工厂和MQ消费者监听器工厂

package com.example.mq.config;

import com.example.mq.config.properties.ActiveMqConfigProperties;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.



版权声明:本文为baidu_41208204原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。