@@ -78,6 +78,41 @@ public WxCpTpMessageRouter(WxCpTpService wxCpTpService) {
78
78
this .exceptionHandler = new LogExceptionHandler ();
79
79
}
80
80
81
+ /**
82
+ * 使用自定义的 {@link ExecutorService}.
83
+ */
84
+ public WxCpTpMessageRouter (WxCpTpService wxCpTpService , ExecutorService executorService ) {
85
+ this .wxCpTpService = wxCpTpService ;
86
+ this .executorService = executorService ;
87
+ this .messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker ();
88
+ this .sessionManager = wxCpTpService .getSessionManager ();
89
+ this .exceptionHandler = new LogExceptionHandler ();
90
+ }
91
+
92
+ /**
93
+ * 系统退出前,应该调用该方法
94
+ */
95
+ public void shutDownExecutorService () {
96
+ this .executorService .shutdown ();
97
+ }
98
+
99
+ /**
100
+ * 系统退出前,应该调用该方法,增加了超时时间检测
101
+ */
102
+ public void shutDownExecutorService (Integer second ) {
103
+ this .executorService .shutdown ();
104
+ try {
105
+ if (!this .executorService .awaitTermination (second , TimeUnit .SECONDS )) {
106
+ this .executorService .shutdownNow ();
107
+ if (!this .executorService .awaitTermination (second , TimeUnit .SECONDS ))
108
+ log .error ("线程池未关闭!" );
109
+ }
110
+ } catch (InterruptedException ie ) {
111
+ this .executorService .shutdownNow ();
112
+ Thread .currentThread ().interrupt ();
113
+ }
114
+ }
115
+
81
116
/**
82
117
* <pre>
83
118
* 设置自定义的 {@link ExecutorService}
@@ -200,30 +235,29 @@ public WxCpXmlOutMessage route(final WxCpTpXmlMessage wxMessage) {
200
235
201
236
private boolean isMsgDuplicated (WxCpTpXmlMessage wxMessage ) {
202
237
StringBuilder messageId = new StringBuilder ();
203
- if (wxMessage .getInfoType () != null ) {
204
- messageId .append (wxMessage .getInfoType ())
205
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getSuiteId ()))
206
- .append ("-" ).append (wxMessage .getTimeStamp ())
207
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getAuthCorpId ()))
208
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getUserID ()))
209
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getChangeType ()))
210
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getServiceCorpId ()));
211
- }
238
+ if (wxMessage .getInfoType () != null ) {
239
+ messageId .append (wxMessage .getInfoType ())
240
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getSuiteId ()))
241
+ .append ("-" ).append (wxMessage .getTimeStamp ())
242
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getAuthCorpId ()))
243
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getUserID ()))
244
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getChangeType ()))
245
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getServiceCorpId ()));
246
+ }
212
247
213
- if (wxMessage .getMsgType () != null ) {
214
- if (wxMessage .getMsgId () != null ) {
215
- messageId .append (wxMessage .getMsgId ())
216
- .append ("-" ).append (wxMessage .getCreateTime ())
217
- .append ("-" ).append (wxMessage .getFromUserName ());
218
- }
219
- else {
220
- messageId .append (wxMessage .getMsgType ())
221
- .append ("-" ).append (wxMessage .getCreateTime ())
222
- .append ("-" ).append (wxMessage .getFromUserName ())
223
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getEvent ()))
224
- .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getEventKey ()));
225
- }
248
+ if (wxMessage .getMsgType () != null ) {
249
+ if (wxMessage .getMsgId () != null ) {
250
+ messageId .append (wxMessage .getMsgId ())
251
+ .append ("-" ).append (wxMessage .getCreateTime ())
252
+ .append ("-" ).append (wxMessage .getFromUserName ());
253
+ } else {
254
+ messageId .append (wxMessage .getMsgType ())
255
+ .append ("-" ).append (wxMessage .getCreateTime ())
256
+ .append ("-" ).append (wxMessage .getFromUserName ())
257
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getEvent ()))
258
+ .append ("-" ).append (StringUtils .trimToEmpty (wxMessage .getEventKey ()));
226
259
}
260
+ }
227
261
228
262
return this .messageDuplicateChecker .isDuplicate (messageId .toString ());
229
263
}
0 commit comments