mirror of
https://github.com/didi/KnowStreaming.git
synced 2026-01-04 20:02:07 +08:00
kafka-manager 2.0
This commit is contained in:
37
kafka-manager-extends/kafka-manager-notify/pom.xml
Normal file
37
kafka-manager-extends/kafka-manager-notify/pom.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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>kafka-manager</artifactId>
|
||||
<groupId>com.xiaojukeji.kafka</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>kafka-manager-notify</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xiaojukeji.kafka</groupId>
|
||||
<artifactId>kafka-manager-common</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>5.0.9.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.xiaojukeji.kafka</groupId>
|
||||
<artifactId>kafka-manager-core</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.xiaojukeji.kafka.manager.notify;
|
||||
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.entity.ao.account.Account;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.OrderDO;
|
||||
import com.xiaojukeji.kafka.manager.common.events.OrderApplyEvent;
|
||||
import com.xiaojukeji.kafka.manager.notify.common.NotifyConstant;
|
||||
import com.xiaojukeji.kafka.manager.notify.notifyer.AbstractNotifyService;
|
||||
import com.xiaojukeji.kafka.manager.notify.common.OrderNotifyTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/8/27
|
||||
*/
|
||||
@Service("orderApplyNotifyService")
|
||||
public class OrderApplyNotifyService implements ApplicationListener<OrderApplyEvent> {
|
||||
@Autowired
|
||||
private AbstractNotifyService notifyService;
|
||||
|
||||
@Value("${notify.order.detail-url}")
|
||||
private String orderDetailUrl;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(OrderApplyEvent orderApplyEvent) {
|
||||
OrderDO orderDO = orderApplyEvent.getOrderDO();
|
||||
String detailUrl = String.format(orderDetailUrl, orderDO.getId(), orderApplyEvent.getIdc());
|
||||
for (Account account : NotifyConstant.accountList) {
|
||||
notifyService.sendMsg(account.getUsername(),
|
||||
OrderNotifyTemplate.getNotify2OrderHandlerMessage(
|
||||
account.getChineseName(),
|
||||
orderDO.getApplicant(),
|
||||
orderDO.getTitle(),
|
||||
detailUrl
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xiaojukeji.kafka.manager.notify;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.OrderDO;
|
||||
import com.xiaojukeji.kafka.manager.common.events.OrderPassedEvent;
|
||||
import com.xiaojukeji.kafka.manager.notify.common.OrderNotifyTemplate;
|
||||
import com.xiaojukeji.kafka.manager.notify.notifyer.AbstractNotifyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/8/27
|
||||
*/
|
||||
@Service("orderPassedNotifyService")
|
||||
public class OrderPassedNotifyService implements ApplicationListener<OrderPassedEvent> {
|
||||
@Autowired
|
||||
private AbstractNotifyService notifyService;
|
||||
|
||||
@Value("${notify.order.detail-url}")
|
||||
private String orderDetailUrl;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(OrderPassedEvent orderPassEvent) {
|
||||
OrderDO orderDO = orderPassEvent.getOrderDO();
|
||||
String detailUrl = String.format(orderDetailUrl, orderDO.getId(), orderPassEvent.getIdc());
|
||||
notifyService.sendMsg(orderDO.getApplicant(),
|
||||
OrderNotifyTemplate.getNotifyOrderPassed2ApplicantMessage(
|
||||
orderDO.getApplicant(),
|
||||
orderDO.getTitle(),
|
||||
detailUrl
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xiaojukeji.kafka.manager.notify;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.entity.pojo.OrderDO;
|
||||
import com.xiaojukeji.kafka.manager.common.events.OrderRefusedEvent;
|
||||
import com.xiaojukeji.kafka.manager.notify.common.OrderNotifyTemplate;
|
||||
import com.xiaojukeji.kafka.manager.notify.notifyer.AbstractNotifyService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/8/27
|
||||
*/
|
||||
@Service("orderRefusedNotifyService")
|
||||
public class OrderRefusedNotifyService implements ApplicationListener<OrderRefusedEvent> {
|
||||
@Autowired
|
||||
private AbstractNotifyService notifyService;
|
||||
|
||||
@Value("${notify.order.detail-url}")
|
||||
private String orderDetailUrl;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(OrderRefusedEvent orderRefuseEvent) {
|
||||
OrderDO orderDO = orderRefuseEvent.getOrderDO();
|
||||
String detailUrl = String.format(orderDetailUrl, orderDO.getId(), orderRefuseEvent.getIdc());
|
||||
notifyService.sendMsg(orderDO.getApplicant(),
|
||||
OrderNotifyTemplate.getNotifyOrderRefused2ApplicantMessage(
|
||||
orderDO.getApplicant(),
|
||||
orderDO.getTitle(),
|
||||
detailUrl
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.xiaojukeji.kafka.manager.notify.common;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.common.bizenum.AccountRoleEnum;
|
||||
import com.xiaojukeji.kafka.manager.common.entity.ao.account.Account;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/8/27
|
||||
*/
|
||||
public class NotifyConstant {
|
||||
|
||||
public static final List<Account> accountList = Arrays.asList(
|
||||
new Account("xuzhengxi", "徐正熙", "", AccountRoleEnum.OP)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.xiaojukeji.kafka.manager.notify.common;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/09/03
|
||||
*/
|
||||
public class OrderNotifyTemplate {
|
||||
private static String NOTIFY_HANDLER_TEMPLATE = "%s,您好!您收到来自%s的申请工单:“%s”请及时审批。如需查看详情,请前往 %s";
|
||||
public static String getNotify2OrderHandlerMessage(String username,
|
||||
String applicant,
|
||||
String title,
|
||||
String orderDetailUrl) {
|
||||
return String.format(
|
||||
NOTIFY_HANDLER_TEMPLATE,
|
||||
username,
|
||||
applicant,
|
||||
title,
|
||||
orderDetailUrl
|
||||
);
|
||||
}
|
||||
|
||||
private static String NOTIFY_ORDER_PASSED_TEMPLATE = "%s,您好!您的申请工单:“%s”已完成审批,结果为:通过。如需查看详情,请前往 %s";
|
||||
public static String getNotifyOrderPassed2ApplicantMessage(String username,
|
||||
String title,
|
||||
String orderDetailUrl) {
|
||||
return String.format(NOTIFY_ORDER_PASSED_TEMPLATE,
|
||||
username,
|
||||
title,
|
||||
orderDetailUrl
|
||||
);
|
||||
}
|
||||
|
||||
private static String NOTIFY_ORDER_REFUSED_TEMPLATE = "%s,您好!您的申请工单:“%s”已完成审批,结果为:拒绝。如需查看详情,请前往 %s";
|
||||
public static String getNotifyOrderRefused2ApplicantMessage(String username,
|
||||
String title,
|
||||
String orderDetailUrl) {
|
||||
return String.format(NOTIFY_ORDER_REFUSED_TEMPLATE,
|
||||
username,
|
||||
title,
|
||||
orderDetailUrl
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.xiaojukeji.kafka.manager.notify.notifyer;
|
||||
|
||||
public abstract class AbstractNotifyService {
|
||||
public abstract boolean sendMsg(String username, String content);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.xiaojukeji.kafka.manager.notify.notifyer;
|
||||
|
||||
import com.xiaojukeji.kafka.manager.service.cache.KafkaClientPool;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zengqiao
|
||||
* @date 20/9/25
|
||||
*/
|
||||
@Service("notifyService")
|
||||
public class KafkaNotifierService extends AbstractNotifyService {
|
||||
@Value("${kafka.cluster-id:}")
|
||||
private Long clusterId;
|
||||
|
||||
@Value("${notify.topic-name:}")
|
||||
private String topicName;
|
||||
|
||||
@Override
|
||||
public boolean sendMsg(String username, String content) {
|
||||
KafkaClientPool.produceData2Kafka(clusterId, topicName, content);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
notify:
|
||||
order:
|
||||
detail-url: http://127.0.0.1
|
||||
|
||||
kafka:
|
||||
cluster-id: 12
|
||||
topic-name: 123
|
||||
|
||||
Reference in New Issue
Block a user