parent
aadaa17108
commit
0b854ceb7d
@ -0,0 +1,62 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>beacon-cloud</artifactId>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>beacon-monitor</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- nacos注册-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- nacos配置-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- 公共模块-->
|
||||
<dependency>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<artifactId>beacon-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- xxl-job的依赖-->
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RabbitMQ依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!-- openFeign-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- JavaMail-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
package com.mashibing.monitor;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @author dch
|
||||
* @create 2024-03-28 10:20
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class MonitorStarterApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MonitorStarterApp.class,args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mashibing.monitor.client;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author dch
|
||||
* @create 2024-03-20 11:54
|
||||
*/
|
||||
@FeignClient("beacon-cache")
|
||||
public interface CacheClient {
|
||||
|
||||
@PostMapping(value = "/cache/keys/{pattern}")
|
||||
Set<String> keys(@PathVariable(value = "pattern") String pattern);
|
||||
|
||||
@GetMapping("/cache/hgetall/{key}")
|
||||
Map hGetAll(@PathVariable(value = "key") String key);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.mashibing.monitor.config;
|
||||
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author dch
|
||||
* @create 2024-03-28 11:08
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class XxlJobConfig {
|
||||
|
||||
|
||||
@Value("${xxl.job.admin.addresses}")
|
||||
private String adminAddresses;
|
||||
|
||||
@Value("${xxl.job.accessToken}")
|
||||
private String accessToken;
|
||||
|
||||
@Value("${xxl.job.executor.appname}")
|
||||
private String appname;
|
||||
|
||||
@Value("${xxl.job.executor.address}")
|
||||
private String address;
|
||||
|
||||
@Value("${xxl.job.executor.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${xxl.job.executor.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${xxl.job.executor.logpath}")
|
||||
private String logPath;
|
||||
|
||||
@Value("${xxl.job.executor.logretentiondays}")
|
||||
private int logRetentionDays;
|
||||
|
||||
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||
log.info(">>>>>>>>>>> xxl-job config init.");
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||
xxlJobSpringExecutor.setAppname(appname);
|
||||
xxlJobSpringExecutor.setIp(ip);
|
||||
xxlJobSpringExecutor.setPort(port);
|
||||
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||
xxlJobSpringExecutor.setLogPath(logPath);
|
||||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||
return xxlJobSpringExecutor;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.mashibing.monitor.task;
|
||||
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author dch
|
||||
* @create 2024-03-28 15:57
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TestTask {
|
||||
|
||||
@XxlJob("test")
|
||||
public void test(){
|
||||
// 编写任务逻辑
|
||||
log.info("Hello World!");
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.mashibing.monitor.util;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
/**
|
||||
* @author dch
|
||||
* @create 2024-03-28 17:05
|
||||
*/
|
||||
@Component
|
||||
@RefreshScope
|
||||
public class MailUtil {
|
||||
|
||||
@Value("${spring.mail.username}")
|
||||
private String from;
|
||||
|
||||
@Value("${spring.mail.tos}")
|
||||
private String tos;
|
||||
|
||||
// @Autowired
|
||||
@Resource
|
||||
private JavaMailSender javaMailSender;
|
||||
|
||||
|
||||
public void sendEmail(String subject,String text) throws MessagingException {
|
||||
// 构建MimeMessage对象
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
|
||||
// 给邮件指定信息
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
|
||||
helper.setFrom(from);
|
||||
helper.setTo(tos.split(","));
|
||||
helper.setSubject(subject);
|
||||
helper.setText(text);
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
|
||||
|
||||
public void sendEmail(String to, String subject, String text) throws MessagingException {
|
||||
// 构建MimeMessage对象
|
||||
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||
|
||||
// 给邮件指定信息
|
||||
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
|
||||
helper.setFrom(from);
|
||||
helper.setTo(to);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(text);
|
||||
|
||||
// 发送邮件
|
||||
javaMailSender.send(mimeMessage);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
# 服务名称
|
||||
spring:
|
||||
application:
|
||||
name: beacon-monitor
|
||||
# 多环境
|
||||
profiles:
|
||||
active: dev
|
||||
# nacos注册中心地址
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.1.127:8848
|
||||
# nacos配置中心地址:
|
||||
config:
|
||||
server-addr: 192.168.1.127:8848
|
||||
file-extension: yml
|
||||
# beacon-monitor-dev.yml
|
Loading…
Reference in new issue