作者 朱兆平

kafka消息总线路由管理

package com.sunyo.wlpt.message.bus.service.controller;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequestMapping("router")
@RestController
public class RouterController {
@ApiOperation(value = "批量添加消息路由", notes = "超级管理修改其他用户密码")
@PostMapping
public void batchAddRouter(){
@PostMapping("batchAdd")
public void batchAddRouter(@RequestBody MessageRouter messageRouter){
... ...
package com.sunyo.wlpt.message.bus.service.model;
import java.util.Date;
import java.util.List;
public class MessageRouter {
private String id;
... ... @@ -19,7 +20,7 @@ public class MessageRouter {
private Boolean status;
private Boolean usage;
private Integer usage;
private String des;
... ... @@ -29,6 +30,12 @@ public class MessageRouter {
private Date updateTime;
private List<String> sndrs;
private List<MessageType> types;
private List<String> rcvrs;
public String getId() {
return id;
}
... ... @@ -93,11 +100,11 @@ public class MessageRouter {
this.status = status;
}
public Boolean getUsage() {
public Integer getUsage() {
return usage;
}
public void setUsage(Boolean usage) {
public void setUsage(Integer usage) {
this.usage = usage;
}
... ... @@ -132,4 +139,28 @@ public class MessageRouter {
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public List<String> getSndrs() {
return sndrs;
}
public void setSndrs(List<String> sndrs) {
this.sndrs = sndrs;
}
public List<MessageType> getTypes() {
return types;
}
public void setTypes(List<MessageType> types) {
this.types = types;
}
public List<String> getRcvrs() {
return rcvrs;
}
public void setRcvrs(List<String> rcvrs) {
this.rcvrs = rcvrs;
}
}
\ No newline at end of file
... ...
package com.sunyo.wlpt.message.bus.service.service;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
public interface RouterService {
boolean batchAddRouter(MessageRouter messageRouter);
}
... ...
package com.sunyo.wlpt.message.bus.service.service.impl;
import com.sunyo.wlpt.message.bus.service.model.MessageRouter;
import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
import com.sunyo.wlpt.message.bus.service.service.RouterService;
import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
import java.util.List;
public class RouterServiceImp implements RouterService {
@Override
public boolean batchAddRouter(MessageRouter record) {
List<String> senders = record.getSndrs();
if (senders!=null && !senders.isEmpty()){
/**
* 批量增加发送者表
*/
for (String sndr: senders) {
String id = IdUtils.generateId();
MessageRouter router = new MessageRouter();
router.setId(id);
router.setSndr(sndr);
router.setDes(record.getDes());
router.setVer(record.getVer());
router.setStatus(record.getStatus());
router.setUsage(record.getUsage());
/**
* 批量增加接收者表
*/
List<String> receivers = record.getRcvrs();
if (receivers!=null && !receivers.isEmpty()){
for (String rcvr :receivers) {
MessageRouterReciver messageRouterReciver = new MessageRouterReciver();
messageRouterReciver.setId(id);
messageRouterReciver.setMessageRouterId(id);
messageRouterReciver.setRcvrTopic(rcvr);
}
}
}
}
return false;
}
}
... ...
... ... @@ -10,7 +10,7 @@
<result column="msg_limit" property="msgLimit" jdbcType="TINYINT" />
<result column="character" property="character" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="BIT" />
<result column="usage" property="usage" jdbcType="BIT" />
<result column="usage" property="usage" jdbcType="TINYINT" />
<result column="des" property="des" jdbcType="VARCHAR" />
<result column="ver" property="ver" jdbcType="VARCHAR" />
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
... ... @@ -38,7 +38,7 @@
)
values (#{id,jdbcType=VARCHAR}, #{sndr,jdbcType=VARCHAR}, #{btype,jdbcType=VARCHAR},
#{stype,jdbcType=VARCHAR}, #{optype,jdbcType=VARCHAR}, #{msgLimit,jdbcType=TINYINT},
#{character,jdbcType=VARCHAR}, #{status,jdbcType=BIT}, #{usage,jdbcType=BIT}, #{des,jdbcType=VARCHAR},
#{character,jdbcType=VARCHAR}, #{status,jdbcType=BIT}, #{usage,jdbcType=TINYINT}, #{des,jdbcType=VARCHAR},
#{ver,jdbcType=VARCHAR}, #{creatTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
)
</insert>
... ... @@ -111,7 +111,7 @@
#{status,jdbcType=BIT},
</if>
<if test="usage != null" >
#{usage,jdbcType=BIT},
#{usage,jdbcType=TINYINT},
</if>
<if test="des != null" >
#{des,jdbcType=VARCHAR},
... ... @@ -152,7 +152,7 @@
status = #{status,jdbcType=BIT},
</if>
<if test="usage != null" >
usage = #{usage,jdbcType=BIT},
usage = #{usage,jdbcType=TINYINT},
</if>
<if test="des != null" >
des = #{des,jdbcType=VARCHAR},
... ... @@ -178,7 +178,7 @@
msg_limit = #{msgLimit,jdbcType=TINYINT},
character = #{character,jdbcType=VARCHAR},
status = #{status,jdbcType=BIT},
usage = #{usage,jdbcType=BIT},
usage = #{usage,jdbcType=TINYINT},
des = #{des,jdbcType=VARCHAR},
ver = #{ver,jdbcType=VARCHAR},
creat_time = #{creatTime,jdbcType=TIMESTAMP},
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverFilterMapper" >
<resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="filter" property="filter" jdbcType="VARCHAR" />
<result column="filter_value" property="filterValue" jdbcType="VARCHAR" />
<result column="type" property="type" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="BIT" />
<result column="message_router_reciver_id" property="messageRouterReciverId" jdbcType="VARCHAR" />
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverFilterMapper">
<resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="filter" jdbcType="VARCHAR" property="filter" />
<result column="filter_value" jdbcType="VARCHAR" property="filterValue" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="status" jdbcType="BIT" property="status" />
<result column="message_router_reciver_id" jdbcType="VARCHAR" property="messageRouterReciverId" />
<result column="creat_time" jdbcType="TIMESTAMP" property="creatTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List" >
<sql id="Base_Column_List">
id, filter, filter_value, type, status, message_router_reciver_id, creat_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from message_router_reciver_filter
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from message_router_reciver_filter
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" >
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter">
insert into message_router_reciver_filter (id, filter, filter_value,
type, status, message_router_reciver_id,
creat_time, update_time)
... ... @@ -32,89 +32,89 @@
#{type,jdbcType=VARCHAR}, #{status,jdbcType=BIT}, #{messageRouterReciverId,jdbcType=VARCHAR},
#{creatTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" >
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter">
insert into message_router_reciver_filter
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="filter != null" >
<if test="filter != null">
filter,
</if>
<if test="filterValue != null" >
<if test="filterValue != null">
filter_value,
</if>
<if test="type != null" >
<if test="type != null">
type,
</if>
<if test="status != null" >
<if test="status != null">
status,
</if>
<if test="messageRouterReciverId != null" >
<if test="messageRouterReciverId != null">
message_router_reciver_id,
</if>
<if test="creatTime != null" >
<if test="creatTime != null">
creat_time,
</if>
<if test="updateTime != null" >
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="filter != null" >
<if test="filter != null">
#{filter,jdbcType=VARCHAR},
</if>
<if test="filterValue != null" >
<if test="filterValue != null">
#{filterValue,jdbcType=VARCHAR},
</if>
<if test="type != null" >
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="status != null" >
<if test="status != null">
#{status,jdbcType=BIT},
</if>
<if test="messageRouterReciverId != null" >
<if test="messageRouterReciverId != null">
#{messageRouterReciverId,jdbcType=VARCHAR},
</if>
<if test="creatTime != null" >
<if test="creatTime != null">
#{creatTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" >
<update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter">
update message_router_reciver_filter
<set >
<if test="filter != null" >
<set>
<if test="filter != null">
filter = #{filter,jdbcType=VARCHAR},
</if>
<if test="filterValue != null" >
<if test="filterValue != null">
filter_value = #{filterValue,jdbcType=VARCHAR},
</if>
<if test="type != null" >
<if test="type != null">
type = #{type,jdbcType=VARCHAR},
</if>
<if test="status != null" >
<if test="status != null">
status = #{status,jdbcType=BIT},
</if>
<if test="messageRouterReciverId != null" >
<if test="messageRouterReciverId != null">
message_router_reciver_id = #{messageRouterReciverId,jdbcType=VARCHAR},
</if>
<if test="creatTime != null" >
<if test="creatTime != null">
creat_time = #{creatTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter" >
<update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.model.MessageRouterReciverFilter">
update message_router_reciver_filter
set filter = #{filter,jdbcType=VARCHAR},
filter_value = #{filterValue,jdbcType=VARCHAR},
... ...