@@ -0,0 +1,59 @@ | |||||
package com.xkcoding.mq.rabbitmq.config; | |||||
import com.xkcoding.mq.rabbitmq.constants.RabbitConsts; | |||||
import org.springframework.amqp.core.DirectExchange; | |||||
import org.springframework.amqp.core.FanoutExchange; | |||||
import org.springframework.amqp.core.Queue; | |||||
import org.springframework.amqp.core.TopicExchange; | |||||
import org.springframework.context.annotation.Bean; | |||||
import org.springframework.context.annotation.Configuration; | |||||
/** | |||||
* <p> | |||||
* RabbitMQ配置,主要是配置队列,如果提前存在该队列,可以省略本配置类 | |||||
* </p> | |||||
* | |||||
* @package: com.xkcoding.mq.rabbitmq.config | |||||
* @description: RabbitMQ配置,主要是配置队列,如果提前存在该队列,可以省略本配置类 | |||||
* @author: yangkai.shen | |||||
* @date: Created in 2018-12-29 17:03 | |||||
* @copyright: Copyright (c) 2018 | |||||
* @version: V1.0 | |||||
* @modified: yangkai.shen | |||||
*/ | |||||
@Configuration | |||||
public class RabbitMqConfig { | |||||
/** | |||||
* 直接模式队列 | |||||
*/ | |||||
@Bean | |||||
public DirectExchange directQueue() { | |||||
return new DirectExchange(RabbitConsts.DIRECT_MODE_QUEUE); | |||||
} | |||||
/** | |||||
* 分列模式队列 | |||||
*/ | |||||
@Bean | |||||
public FanoutExchange fanoutQueue() { | |||||
return new FanoutExchange(RabbitConsts.FANOUT_MODE_QUEUE); | |||||
} | |||||
/** | |||||
* 主题模式队列 | |||||
*/ | |||||
@Bean | |||||
public TopicExchange topicQueue() { | |||||
return new TopicExchange(RabbitConsts.TOPIC_MODE_QUEUE); | |||||
} | |||||
/** | |||||
* 延迟模式队列 | |||||
*/ | |||||
@Bean | |||||
public Queue delayQueue() { | |||||
return new Queue(RabbitConsts.DELAY_MODE_QUEUE, true); | |||||
} | |||||
} |
@@ -0,0 +1,36 @@ | |||||
package com.xkcoding.mq.rabbitmq.constants; | |||||
/** | |||||
* <p> | |||||
* RabbitMQ常量池 | |||||
* </p> | |||||
* | |||||
* @package: com.xkcoding.mq.rabbitmq.constants | |||||
* @description: RabbitMQ常量池 | |||||
* @author: yangkai.shen | |||||
* @date: Created in 2018-12-29 17:08 | |||||
* @copyright: Copyright (c) 2018 | |||||
* @version: V1.0 | |||||
* @modified: yangkai.shen | |||||
*/ | |||||
public interface RabbitConsts { | |||||
/** | |||||
* 直接模式 | |||||
*/ | |||||
String DIRECT_MODE_QUEUE = "queue_direct"; | |||||
/** | |||||
* 分列模式 | |||||
*/ | |||||
String FANOUT_MODE_QUEUE = "queue_fanout"; | |||||
/** | |||||
* 主题模式 | |||||
*/ | |||||
String TOPIC_MODE_QUEUE = "queue_topic"; | |||||
/** | |||||
* 延迟模式 | |||||
*/ | |||||
String DELAY_MODE_QUEUE = "delay_topic"; | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package com.xkcoding.mq.rabbitmq.message; | |||||
import lombok.Data; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 测试消息体 | |||||
* </p> | |||||
* | |||||
* @package: com.xkcoding.mq.rabbitmq.message | |||||
* @description: 测试消息体 | |||||
* @author: yangkai.shen | |||||
* @date: Created in 2018-12-29 16:22 | |||||
* @copyright: Copyright (c) 2018 | |||||
* @version: V1.0 | |||||
* @modified: yangkai.shen | |||||
*/ | |||||
@Data | |||||
public class MessageStruct implements Serializable { | |||||
private static final long serialVersionUID = 392365881428311040L; | |||||
private String message; | |||||
} |
@@ -0,0 +1,17 @@ | |||||
server: | |||||
port: 8080 | |||||
servlet: | |||||
context-path: /demo | |||||
spring: | |||||
rabbitmq: | |||||
host: localhost | |||||
port: 5672 | |||||
username: guest | |||||
password: guest | |||||
virtual-host: / | |||||
# 手动提交消息 | |||||
listener: | |||||
simple: | |||||
acknowledge-mode: manual | |||||
direct: | |||||
acknowledge-mode: manual |