es与mq
parent
4f0e881554
commit
83d598dda2
|
@ -2,4 +2,7 @@ package com.bwie.common.constants;
|
|||
|
||||
public class RabbitMQConstants {
|
||||
public static final String SEND_SMS_QUEUE = "send_sms_queue";
|
||||
public static final String SENDCODEQUEUE = "queue_one";
|
||||
public static final String SENDCODEEXCHANGE = "Exchange_one";
|
||||
public static final String SENDCODEKEY = "key_one";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>Java-glob</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bwie-es</artifactId>
|
||||
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>bwie-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.bwie;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
* @date 2024-01-23 19:23
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients(basePackages = {"com.bwie"})
|
||||
@EnableScheduling
|
||||
public class EslactionAppliction {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EslactionAppliction.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.bwie.config;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
* @date 2023-11-29 11:50
|
||||
*/
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "es")
|
||||
@Data
|
||||
public class EsConfig {
|
||||
private String host;
|
||||
private int port;
|
||||
private String scheme;
|
||||
//初始化
|
||||
@Bean
|
||||
public RestHighLevelClient restHighLevelClient(){
|
||||
return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port,scheme)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9005
|
||||
# Spring
|
||||
spring:
|
||||
|
||||
elasticsearch:
|
||||
|
||||
rest:
|
||||
|
||||
uris: http://43.143.161.183:9200
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: bwie-es
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 43.143.161.183:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 43.143.161.183:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
es:
|
||||
host: 43.143.161.183
|
||||
port: 9200
|
||||
scheme: http
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>Java-glob</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bwie-mq</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>bwie-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,12 @@
|
|||
package com.bwie;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
* @date 2023-11-25 8:16
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.bwie;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
* @date 2024-01-23 19:22
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RabbitMqAppliction {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RabbitMqAppliction.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.bwie.mq.config;
|
||||
|
||||
|
||||
import com.bwie.common.constants.RabbitMQConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
/**
|
||||
* @author gxb
|
||||
* @description TODO
|
||||
* @date 2023-12-22 17:19
|
||||
*/
|
||||
@Configuration
|
||||
public class MqConfig implements RabbitTemplate.ConfirmCallback,RabbitTemplate.ReturnsCallback {
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
private static final Logger logger = LoggerFactory.getLogger(MqConfig.class);
|
||||
//消息转换
|
||||
@Bean
|
||||
public MessageConverter messageConverter(){
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
//创建队列
|
||||
@Bean
|
||||
public Queue queue(){
|
||||
return new Queue(RabbitMQConstants.SENDCODEQUEUE,true);
|
||||
}
|
||||
//创建交换机
|
||||
@Bean
|
||||
public DirectExchange directExchange(){
|
||||
return new DirectExchange(RabbitMQConstants.SENDCODEEXCHANGE);
|
||||
}
|
||||
//绑定交换机和队列
|
||||
@Bean
|
||||
public Binding binding(){
|
||||
return BindingBuilder.bind(queue()).to(directExchange()).with(RabbitMQConstants.SENDCODEKEY);
|
||||
}
|
||||
//初始化
|
||||
public void RabbitTemplate(){
|
||||
rabbitTemplate.setConfirmCallback(this);
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
@Primary
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
|
||||
RabbitTemplate rabbitTemplate1 = new RabbitTemplate(connectionFactory);
|
||||
this.rabbitTemplate=rabbitTemplate1;
|
||||
rabbitTemplate.setMessageConverter(messageConverter());
|
||||
RabbitTemplate();
|
||||
return rabbitTemplate1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean b, String s) {
|
||||
if (b){
|
||||
logger.info("{}消息成功到达交换机",correlationData.getId());
|
||||
}else {
|
||||
logger.error("{}消息丢失",correlationData.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
logger.error("{}消息为进入队列",returnedMessage.getMessage().getMessageProperties().getMessageId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9003
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: bwie-mq
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 43.143.161.183:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 43.143.161.183:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
Loading…
Reference in New Issue