mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
支持rabbitmq
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -51,6 +51,10 @@
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
|
||||
@@ -27,6 +27,9 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.jgrapht.graph.DefaultDirectedGraph;
|
||||
import org.jgrapht.graph.DefaultEdge;
|
||||
import org.jgrapht.traverse.TopologicalOrderIterator;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -43,8 +46,8 @@ import java.util.Optional;
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public
|
||||
class CoalParameterDefService extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
|
||||
public class CoalParameterDefService
|
||||
extends BaseService<CoalParameterDefEntity, CoalParameterDefRepository> {
|
||||
|
||||
@Autowired CoalParameterDefRepository repository;
|
||||
|
||||
@@ -177,6 +180,22 @@ class CoalParameterDefService extends BaseService<CoalParameterDefEntity, CoalPa
|
||||
.forEach(organizationEntity -> initDefault(organizationEntity.getId()));
|
||||
}
|
||||
|
||||
@RabbitListener(
|
||||
bindings = {
|
||||
@QueueBinding(
|
||||
value =
|
||||
@org.springframework.amqp.rabbit.annotation.Queue(
|
||||
value = "coalParameterDef.init",
|
||||
durable = "true"),
|
||||
exchange =
|
||||
@org.springframework.amqp.rabbit.annotation.Exchange(
|
||||
value = "sysExchange", declare = Exchange.FALSE),
|
||||
key = "organization.create")
|
||||
})
|
||||
public void onOrganizationCreate(String orgId) {
|
||||
initDefault(orgId);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void initDefault(String orgId) {
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.lihongjie.coal.organization.dto.UpdateOrganizationDto;
|
||||
import cn.lihongjie.coal.organization.entity.OrganizationEntity;
|
||||
import cn.lihongjie.coal.organization.mapper.OrganizationMapper;
|
||||
import cn.lihongjie.coal.organization.repository.OrganizationRepository;
|
||||
import cn.lihongjie.coal.rabbitmq.RabbitMQService;
|
||||
import cn.lihongjie.coal.user.dto.CreateOrgAdminDto;
|
||||
import cn.lihongjie.coal.user.service.UserService;
|
||||
|
||||
@@ -17,6 +18,7 @@ import jakarta.annotation.PostConstruct;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -42,10 +44,13 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
|
||||
@Autowired CoalParameterDefService coalParameterDefService;
|
||||
|
||||
@Autowired RabbitMQService rabbitMQService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {}
|
||||
|
||||
@Autowired RabbitTemplate rabbitTemplate;
|
||||
|
||||
public OrganizationDto create(CreateOrganizationDto request) {
|
||||
|
||||
OrganizationEntity entity = mapper.toEntity(request);
|
||||
@@ -57,7 +62,7 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
dto.setUsername(request.getOrgAdminUserName());
|
||||
dto.setPassword(request.getOrgAdminPassword());
|
||||
userService.createOrgAdmin(dto);
|
||||
coalParameterDefService.initDefault(entity.getId());
|
||||
rabbitMQService.sendToSysExchange("organization.create", entity.getId());
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
@@ -66,7 +71,7 @@ class OrganizationService extends BaseService<OrganizationEntity, OrganizationRe
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
rabbitMQService.sendToSysExchange("organization.update", entity.getId());
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.rabbitmq;
|
||||
|
||||
import org.springframework.amqp.core.TopicExchange;
|
||||
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@EnableRabbit
|
||||
@Configuration
|
||||
public class RabbitMQConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public TopicExchange topicExchange() {
|
||||
return new TopicExchange("sysExchange", true, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.lihongjie.coal.rabbitmq;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RabbitMQService {
|
||||
|
||||
@Autowired RabbitTemplate rabbitTemplate;
|
||||
|
||||
public void send(String exchange, String routingKey, String data){
|
||||
|
||||
rabbitTemplate.convertAndSend(exchange, routingKey, data);
|
||||
}
|
||||
|
||||
public void sendToSysExchange(String routingKey, String data) {
|
||||
send("sysExchange", routingKey, data);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,12 @@ management:
|
||||
|
||||
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: ${RABBITMQ_HOST:localhost}
|
||||
port: ${RABBITMQ_PORT:5672}
|
||||
username: ${RABBITMQ_USER:coal}
|
||||
password: ${RABBITMQ_PASSWORD:coal}
|
||||
virtual-host: ${RABBITMQ_VHOST:/coal}
|
||||
quartz:
|
||||
jdbc:
|
||||
initialize-schema: NEVER
|
||||
|
||||
Reference in New Issue
Block a user