作者 王勇

完善删除配置关系时数据库与MQ服务器的一致性问题

... ... @@ -38,7 +38,7 @@ spring:
port: 5672
username: rabbit
password: 123456
virtual-host: V_zicheng
virtual-host: /
# 开启手动ack机制
# listener:
# simple:
... ...
... ... @@ -159,4 +159,11 @@ public interface UserMessageBindingMapper {
*/
List<UserMessageBinding> validateXmlBinding(XmlData xmlData);
/**
* 进行校验该MQ上的绑定关系,是否存在
*
* @param userMessageBinding {@link UserMessageBinding}
* @return 配置关系,集合
*/
List<UserMessageBinding> validateRabbitBinding(UserMessageBinding userMessageBinding);
}
\ No newline at end of file
... ...
... ... @@ -66,7 +66,9 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService
for (int i = 0; i < split.length; i++) {
UserMessageBinding userMessageBinding = selectByPrimaryKey(split[i]);
int num = userMessageBindingMapper.deleteByPrimaryKey(split[i]);
deleteBinding(userMessageBinding);
if (validateRabbitBinding(userMessageBinding).size() == 0) {
deleteBinding(userMessageBinding);
}
if (num > 0) {
index = index + num;
}
... ... @@ -83,12 +85,25 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService
} else {
UserMessageBinding userMessageBinding = selectByPrimaryKey(id);
int num = userMessageBindingMapper.deleteByPrimaryKey(id);
deleteBinding(userMessageBinding);
if (validateRabbitBinding(userMessageBinding).size() == 0) {
deleteBinding(userMessageBinding);
}
return num;
}
}
/**
* 进行校验该MQ上的绑定关系,是否存在
*
* @param userMessageBinding {@link UserMessageBinding}
* @return 配置关系,集合
*/
public List<UserMessageBinding> validateRabbitBinding(UserMessageBinding userMessageBinding)
{
return userMessageBindingMapper.validateRabbitBinding(userMessageBinding);
}
/**
* 解除MQ服务器上的绑定关系
*/
public void deleteBinding(UserMessageBinding userMessageBinding) throws IOException, TimeoutException
... ...
... ... @@ -364,12 +364,12 @@
from user_message_binding
<where>
<!-- 所属用户id -->
<!-- <if test="userId != null and userId != ''">-->
<!-- user_id = #{userId,jdbcType=VARCHAR}-->
<!-- </if>-->
<if test="username != null and username != ''">
AND username = #{username,jdbcType=VARCHAR}
</if>
<!-- <if test="userId != null and userId != ''">-->
<!-- user_id = #{userId,jdbcType=VARCHAR}-->
<!-- </if>-->
<if test="username != null and username != ''">
AND username = #{username,jdbcType=VARCHAR}
</if>
<!-- 所属服务器id -->
<if test="serverId != null and serverId != ''">
AND server_id = #{serverId,jdbcType=VARCHAR}
... ... @@ -399,8 +399,8 @@
from user_message_binding
<where>
<!-- 所属用户id -->
<if test="userId != null and userId != ''">
user_id = #{userId,jdbcType=VARCHAR}
<if test="username != null and username != ''">
username = #{username,jdbcType=VARCHAR}
</if>
<!-- 所属服务器id -->
<if test="serverId != null and serverId != ''">
... ... @@ -449,4 +449,16 @@
</if>
</where>
</select>
<select id="validateRabbitBinding" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from user_message_binding
<where>
queue_name = #{queueName,jdbcType=VARCHAR}
AND exchange_name = #{exchangeName,jdbcType=VARCHAR}
AND routing_key_name = #{routingKeyName,jdbcType=VARCHAR}
</where>
</select>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<MSG>
<META>
<SNDR>zicheng</SNDR>
<RCVR></RCVR>
<DDTM>2020728151024</DDTM>
<TYPE>E_zicheng</TYPE>
<STYP>R_zicheng</STYP>
<SEQN>12345</SEQN>
<TOKN>token</TOKN>
<VSHT>V_zicheng</VSHT>
<SERV>S_server</SERV>
</META>
<BODY>测试一下,发送xml,进行解析</BODY>
</MSG><!-- 根标签,结束 -->