智能图像处理平台: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;
    }
}
相关推荐
一零贰肆1 分钟前
深入理解SpringBoot中的SpringCache缓存技术
java·springboot·springcache·缓存技术
码上飞扬40 分钟前
Java大师成长计划之第22天:Spring Cloud微服务架构
java·运维·云计算
秋野酱1 小时前
基于javaweb的SpringBoot自习室预约系统设计与实现(源码+文档+部署讲解)
java·spring boot·后端
面试官E先生1 小时前
【极兔快递Java社招】一面复盘|数据库+线程池+AQS+中间件面面俱到
java·面试
琢磨先生David1 小时前
构建优雅对象的艺术:Java 建造者模式的架构解析与工程实践
java·设计模式·建造者模式
小雅痞2 小时前
[Java][Leetcode simple]26. 删除有序数组中的重复项
java·leetcode
青云交2 小时前
Java 大视界 -- 基于 Java 的大数据分布式存储在工业互联网海量设备数据长期存储中的应用优化(248)
java·大数据·工业互联网·分布式存储·冷热数据管理·hbase 优化·kudu 应用
纸包鱼最好吃2 小时前
java基础-package关键字、MVC、import关键字
java·开发语言·mvc
唐山柳林2 小时前
城市生命线综合管控系统解决方案-守护城市生命线安全
java·安全·servlet
PgSheep2 小时前
Spring Cloud Gateway 聚合 Swagger 文档:一站式API管理解决方案
java·开发语言