智能图像处理平台:RabbitMQ配置

前面我们用Docker拉了rabbitMQ,并集成进了springboot,现在我们先写配置类:

java 复制代码
package com.llpp.config;

import com.llpp.service.impl.ImageServiceImpl;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String EXCHANGE_NAME = "image_processing_exchange";
    public static final String QUEUE_NAME = "image_processing_queue";
    public static final String ROUTING_KEY = "image.processing";

    @Autowired
    private ConnectionFactory connectionFactory;

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(EXCHANGE_NAME);
    }

    @Bean
    public Queue queue() {
        return new Queue(QUEUE_NAME, true);
    }

    @Bean
    public Binding binding(Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY);
    }

    @Bean
    public SimpleMessageListenerContainer messageListenerContainer() {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueueNames(QUEUE_NAME);
        container.setMessageListener(new MessageListenerAdapter(new ImageServiceImpl()));
        return container;
    }
}
相关推荐
YDS82911 分钟前
苍穹外卖 —— Spring Task和WebSocket的运用以及订单统一处理、订单的提醒和催单功能的实现
java·spring boot·后端·websocket·spring
速易达网络14 分钟前
C语言常见推理题
java·c语言·算法
m0_6398171517 分钟前
基于springboot纺织品企业财务管理系统【带源码和文档】
java·服务器·前端
q***318320 分钟前
Spring Boot(快速上手)
java·spring boot·后端
q***098024 分钟前
Spring Boot 3.3.4 升级导致 Logback 之前回滚策略配置不兼容问题解决
java·spring boot·logback
羊锦磊1 小时前
[ 项目开发 1.0 ] 新闻网站的开发流程和注意事项
java·数据库·spring boot·redis·spring·oracle·json
吴名氏.2 小时前
电子书《21天学通Java(第5版)》
java·开发语言·21天学通java
曼巴UE52 小时前
UE5 C++ JSON 最简单,麻烦的方式,直接读存(一)
java·服务器·前端
QMY5205202 小时前
什么是爬虫?
java·eclipse