diff --git a/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/config/MqConfig.java b/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/config/MqConfig.java new file mode 100644 index 0000000..852be1f --- /dev/null +++ b/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/config/MqConfig.java @@ -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(); + } +} diff --git a/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/controller/MqController.java b/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/controller/MqController.java index a0ba700..0f80abb 100644 --- a/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/controller/MqController.java +++ b/mystyle-cloud-mq/src/main/java/com/zhangmeng/mq/controller/MqController.java @@ -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; -// } } diff --git a/mystyle-cloud-mq/src/main/resources/application.yml b/mystyle-cloud-mq/src/main/resources/application.yml index 3f0dc9f..5d5ab43 100644 --- a/mystyle-cloud-mq/src/main/resources/application.yml +++ b/mystyle-cloud-mq/src/main/resources/application.yml @@ -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 \ No newline at end of file + server-addr: 127.0.0.1:8848 +mystyle: + security: + open-api: + - /actuator/** + - /instances/** \ No newline at end of file diff --git a/mystyle-cloud-mq/src/main/resources/public.key b/mystyle-cloud-mq/src/main/resources/public.key new file mode 100644 index 0000000..cfceccb --- /dev/null +++ b/mystyle-cloud-mq/src/main/resources/public.key @@ -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----- \ No newline at end of file