2021年12月1日18:23:46

master
zhangmeng 2021-12-01 18:24:05 +08:00
parent b40d043645
commit 44a39a4e2f
4 changed files with 77 additions and 36 deletions

View File

@ -0,0 +1,55 @@
package com.zhangmeng.mq.config;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
@Configuration
public class MqConfig {
private static final String Mail_Queue = "mail.queue";
private static final String Mail_Exchange = "mail.exchange";
private static final String Mail_RoutingKey = "mail.routingKey";
private static final String MyStyle_Cloud_Queue = "mystyle.cloud.queue";
private static final String MyStyle_Cloud_Exchange = "mystyle.cloud.exchange";
private static final String MyStyle_Cloud_RoutingKey = "mystyle.cloud.routingKey";
@Bean
public Queue topicMailQueue() {
return new Queue(Mail_Queue);
}
@Bean
public Queue topicMystyleQueue() {
return new Queue(MyStyle_Cloud_Queue);
}
@Bean
public Exchange topicExchangeMail() {
return new TopicExchange(Mail_Exchange);
}
@Bean
public Exchange topicExchangeMystyle() {
return new TopicExchange(MyStyle_Cloud_Exchange);
}
@Bean
public Binding topicBindingExchangeMail() {
return BindingBuilder.bind(topicMailQueue()).to(topicExchangeMail()).with(Mail_RoutingKey).noargs();
}
@Bean
public Binding topicBindingExchangeMystyle() {
return BindingBuilder.bind(topicMystyleQueue()).to(topicExchangeMystyle()).with(MyStyle_Cloud_RoutingKey).noargs();
}
}

View File

@ -21,39 +21,4 @@ import java.util.Properties;
@RequestMapping("/mq")
public class MqController {
// @Autowired
// private RabbitAdmin rabbitAdmin;
//
// private RabbitTemplate rabbitTemplate;
//
// @PostMapping("/sendMessage")
// public Result sendMessage(String queueName ,String message){
//
// createMQIfNotExist(queueName,queueName);
// return null;
// }
//
// private void createMQIfNotExist(String queueName ,String exchangeName) {
// //判断队列是否存在
// Properties properties = rabbitAdmin.getQueueProperties(queueName);
// if(properties == null){
// Queue queue = new Queue(queueName, true, false, false, null);
// FanoutExchange fanoutExchange = new FanoutExchange(exchangeName);
// rabbitAdmin.declareQueue(queue);
// rabbitAdmin.declareExchange(fanoutExchange);
// rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(fanoutExchange));
//
// String res = callAddNewListener(queueName);
// if(!StringUtils.isEmpty(res)){
// System.out.println("-->>调用创建新的 listener feign 失败");
// }
//
// }
//
//
// }
//
// private String callAddNewListener(String queueName){
// return null;
// }
}

View File

@ -3,6 +3,21 @@ server:
spring:
application:
name: mystyle-cloud-mq
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/mystyle-blog?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
database: mysql
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect
rabbitmq:
host: localhost
port: 5672
@ -20,4 +35,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
server-addr: 127.0.0.1:8848
mystyle:
security:
open-api:
- /actuator/**
- /instances/**

View File

@ -0,0 +1 @@
-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAizuj0fBV2+dj4lM3G6efKYvC2czd07BqmzV++E2yBguVks3XWvsW8qlzmG+t1XBCnRFDI/t1Ddc/Jsnlfy4YzRN8otb/Xn6Yz9ACFvZIPGx/q0cqcrgVaR9rSQiSzsGTgUGHNJk8r3A4w9PSSB552Z9s6p5TsWK5ezlfgg+2ANKn1eJ6R/hzajS/B1bTAqYcl9ddo7prneoeAN5LjlMhc2e0cSVgQt8ALP+4x/bTMnDkMjG6R8lnDAxE27B2ZPaLOIOjkUMK+9mZa4RNBoCDG6J/fwPD1NUoVRCbyr/TVaS4EzyhfNK1QW3BlZ0NLSI/SFD3eryKaFQdacJHS31neQIDAQAB-----END PUBLIC KEY-----