public class WxMpMessageRouter extends Object
微信消息路由器,通过代码化的配置,把来自微信的消息交给handler处理 说明: 1. 配置路由规则时要按照从细到粗的原则,否则可能消息可能会被提前处理 2. 默认情况下消息只会被处理一次,除非使用WxMpMessageRouterRule.next()
3. 规则的结束必须用WxMpMessageRouterRule.end()
或者WxMpMessageRouterRule.next()
,否则不会生效 使用方法: WxMpMessageRouter router = new WxMpMessageRouter(); router .rule() .msgType("MSG_TYPE").event("EVENT").eventKey("EVENT_KEY").content("CONTENT") .interceptor(interceptor, ...).handler(handler, ...) .end() .rule() // 另外一个匹配规则 .end() ; // 将WxXmlMessage交给消息路由器 router.route(message);
构造器和说明 |
---|
WxMpMessageRouter(WxMpService wxMpService)
Instantiates a new Wx mp message router.
|
WxMpMessageRouter(WxMpService wxMpService,
ExecutorService executorService)
使用自定义的
ExecutorService . |
public WxMpMessageRouter(WxMpService wxMpService)
wxMpService
- the wx mp servicepublic WxMpMessageRouter(WxMpService wxMpService, ExecutorService executorService)
ExecutorService
.wxMpService
- the wx mp serviceexecutorService
- the executor servicepublic void shutDownExecutorService()
public void shutDownExecutorService(Integer second)
second
- the secondpublic void setExecutorService(ExecutorService executorService)
设置自定义的 ExecutorService
如果不调用该方法,默认使用 Executors.newFixedThreadPool(100)
executorService
- the executor servicepublic void setMessageDuplicateChecker(WxMessageDuplicateChecker messageDuplicateChecker)
设置自定义的WxMessageDuplicateChecker
如果不调用该方法,默认使用WxMessageInMemoryDuplicateChecker
messageDuplicateChecker
- the message duplicate checkerpublic void setSessionManager(WxSessionManager sessionManager)
设置自定义的WxSessionManager
如果不调用该方法,默认使用StandardSessionManager
sessionManager
- the session managerpublic void setExceptionHandler(WxErrorExceptionHandler exceptionHandler)
设置自定义的WxErrorExceptionHandler
如果不调用该方法,默认使用LogExceptionHandler
exceptionHandler
- the exception handlerpublic WxMpMessageRouterRule rule()
public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, Map<String,Object> context)
wxMessage
- the wx messagecontext
- the contextpublic WxMpXmlOutMessage route(String appid, WxMpXmlMessage wxMessage, Map<String,Object> context)
appid
- the appidwxMessage
- the wx messagecontext
- the contextpublic WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, Map<String,Object> context, WxMpService wxMpService)
wxMessage
- the wx messagecontext
- the contextwxMpService
- the wx mp servicepublic WxMpXmlOutMessage route(WxMpXmlMessage wxMessage)
wxMessage
- the wx messagepublic WxMpXmlOutMessage route(String appid, WxMpXmlMessage wxMessage)
appid
- the appidwxMessage
- the wx messageprotected boolean isMsgDuplicated(WxMpXmlMessage wxMessage)
Copyright © 2024. All rights reserved.