mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 13:03:46 +08:00
issue #66 微信消息去重功能
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* 将每个消息id保存在内存里,每隔5秒清理已经过期的消息id,每个消息id的过期时间是15秒
|
* 将每个消息id保存在内存里,每隔5秒清理已经过期的消息id,每个消息id的过期时间是15秒
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class WxMsgIdInMemoryDuplicateChecker implements WxMsgIdDuplicateChecker {
|
public class WxMsgIdMemoryDuplicateChecker implements WxMsgIdDuplicateChecker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一个消息ID在内存的过期时间:15秒
|
* 一个消息ID在内存的过期时间:15秒
|
||||||
@@ -30,7 +30,7 @@ public class WxMsgIdInMemoryDuplicateChecker implements WxMsgIdDuplicateChecker
|
|||||||
* 每隔多少周期检查消息ID是否过期:5秒
|
* 每隔多少周期检查消息ID是否过期:5秒
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public WxMsgIdInMemoryDuplicateChecker() {
|
public WxMsgIdMemoryDuplicateChecker() {
|
||||||
this.timeToLive = 15 * 1000l;
|
this.timeToLive = 15 * 1000l;
|
||||||
this.clearPeriod = 5 * 1000l;
|
this.clearPeriod = 5 * 1000l;
|
||||||
this.start();
|
this.start();
|
||||||
@@ -41,7 +41,7 @@ public class WxMsgIdInMemoryDuplicateChecker implements WxMsgIdDuplicateChecker
|
|||||||
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
|
* @param timeToLive 一个消息ID在内存的过期时间:毫秒
|
||||||
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
|
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
|
||||||
*/
|
*/
|
||||||
public WxMsgIdInMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {
|
public WxMsgIdMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {
|
||||||
this.timeToLive = timeToLive;
|
this.timeToLive = timeToLive;
|
||||||
this.clearPeriod = clearPeriod;
|
this.clearPeriod = clearPeriod;
|
||||||
this.start();
|
this.start();
|
@@ -3,15 +3,12 @@ package me.chanjar.weixin.common.util;
|
|||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by qianjia on 15/1/20.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public class WxMsgIdInMemoryDuplicateCheckerTest {
|
public class WxMsgIdMemoryDuplicateCheckerTest {
|
||||||
|
|
||||||
public void test() throws InterruptedException {
|
public void test() throws InterruptedException {
|
||||||
Long[] msgIds = new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l };
|
Long[] msgIds = new Long[] { 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l };
|
||||||
WxMsgIdInMemoryDuplicateChecker checker = new WxMsgIdInMemoryDuplicateChecker(2000l, 1000l);
|
WxMsgIdMemoryDuplicateChecker checker = new WxMsgIdMemoryDuplicateChecker(2000l, 1000l);
|
||||||
|
|
||||||
// 第一次检查
|
// 第一次检查
|
||||||
for (Long msgId : msgIds) {
|
for (Long msgId : msgIds) {
|
@@ -1,13 +1,13 @@
|
|||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
<suite name="Weixin-java-tool-suite" verbose="1">
|
<suite name="Weixin-java-tool-suite" verbose="1">
|
||||||
<test name="Bean_Test">
|
<test name="Bean_Test">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="me.chanjar.weixin.common.bean.WxAccessTokenTest" />
|
<class name="me.chanjar.weixin.common.bean.WxAccessTokenTest"/>
|
||||||
<class name="me.chanjar.weixin.common.bean.WxErrorTest" />
|
<class name="me.chanjar.weixin.common.bean.WxErrorTest"/>
|
||||||
<class name="me.chanjar.weixin.common.bean.WxMenuTest" />
|
<class name="me.chanjar.weixin.common.bean.WxMenuTest"/>
|
||||||
<class name="me.chanjar.weixin.common.util.crypto.WxCryptUtilTest" />
|
<class name="me.chanjar.weixin.common.util.crypto.WxCryptUtilTest"/>
|
||||||
<class name="me.chanjar.weixin.common.util.WxMsgIdInMemoryDuplicateCheckerTest" />
|
<class name="me.chanjar.weixin.common.util.WxMsgIdMemoryDuplicateCheckerTest"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
|
Reference in New Issue
Block a user