{"id":10006547,"date":"2022-09-20T13:40:45","date_gmt":"2022-09-20T05:40:45","guid":{"rendered":"https:\/\/ityet.com\/?p=10006547"},"modified":"2022-09-20T13:40:45","modified_gmt":"2022-09-20T05:40:45","slug":"%e8%81%8a%e8%81%8a%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8%e7%ae%a1%e9%81%93%e6%a8%a1%e5%bc%8f%e6%9d%a5%e8%bf%9b%e8%a1%8c%e4%b8%9a%e5%8a%a1%e7%bc%96%e6%8e%92%ef%bc%88%e4%b8%8b%e7%af%87%ef%bc%89","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006547","title":{"rendered":"\u804a\u804a\u5982\u4f55\u5229\u7528\u7ba1\u9053\u6a21\u5f0f\u6765\u8fdb\u884c\u4e1a\u52a1\u7f16\u6392\uff08\u4e0b\u7bc7\uff09"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u4e0a\u7bc7\u6587\u7ae0\u6211\u4eec\u4ecb\u7ecd<a href=\"https:\/\/link.segmentfault.com\/?enc=Zh%2Btsw5bEUeo8%2BWxYcye6Q%3D%3D.m9RG%2FQrDgMmxSO6iqiEduyU%2FAZGFDco4EnItmTMdsFrLS1VxUuUo0m0J6Zg8VaiPKoT7w3WwgaYg7ayo8kTSSDBuoeMFtCI9EuxedGlhnw5mFItIsWXgJYm4AWUyeIHLciRZQia%2FHM8rwf2UWHYijJY%2BxntisJyohJQWAxab9HXcV47n%2BFV5qeQ0jnBF2kTnNeg%2B7oAmeLm9%2FaIjBnPf%2FHhKmB8IwbdqPDDiMv3IMWdTNqfg01Cv4NY8ozCo7T2zEEzzt7jFfo2Np9Px8ncnx5mHyuaiwhbOkyztzVPmXVK8X7NLCux0Tc9%2FJz56BdSs\" rel=\"nofollow\">\u5229\u7528\u7ba1\u9053\u6a21\u5f0f\u6765\u8fdb\u884c\u4e1a\u52a1\u7f16\u6392<\/a>\u76842\u79cd\u5b9e\u73b0\u65b9\u5f0f\u3002\u672c\u6587\u53c8\u6765\u4ecb\u7ecd\u5176\u4ed6\u5b9e\u73b0\u65b9\u5f0f<\/p>\n<h2>\u5b9e\u73b0\u65b9\u5f0f<\/h2>\n<h3>\u65b9\u5f0f\u4e00\uff1a\u5229\u7528springboot\u81ea\u52a8\u88c5\u914d<\/h3>\n<blockquote><p>1\u3001\u65b0\u5efa\u7ba1\u9053\u5b9e\u4f53<\/p><\/blockquote>\n<pre><code class=\"java\">@Data\n@AllArgsConstructor\n@NoArgsConstructor\npublic class PipelineDefinition {\n\n    public static final String PREFIX = &quot;lybgeek_pipeline_&quot;;\n\n    private String comsumePipelineName;\n\n    private List&lt;String&gt; pipelineClassNames;\n}\n<\/code><\/pre>\n<pre><code class=\"java\">@Data\n@AllArgsConstructor\n@NoArgsConstructor\n@ConfigurationProperties(prefix = PipelineDefinitionProperties.PREFIX)\npublic class PipelineDefinitionProperties {\n\n    public final static String PREFIX = &quot;lybgeek.pipeline&quot;;\n\n    private List&lt;PipelineDefinition&gt; chain;\n}\n<\/code><\/pre>\n<blockquote><p>2\u3001\u7f16\u5199\u81ea\u52a8\u88c5\u914d\u7c7b<\/p><\/blockquote>\n<pre><code class=\"java\">@Configuration\n@EnableConfigurationProperties(PipelineDefinitionProperties.class)\npublic class PipelineAutoConfiguration implements BeanFactoryAware,InitializingBean, SmartInitializingSingleton {\n\n\n    @Autowired\n    private PipelineDefinitionProperties pipelineDefinitionProperties;\n\n    private DefaultListableBeanFactory defaultListableBeanFactory;\n\n\n    @Override\n    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {\n\n        defaultListableBeanFactory = (DefaultListableBeanFactory)beanFactory;\n\n    }\n\n    private void registerPipeline(DefaultListableBeanFactory defaultListableBeanFactory, PipelineDefinition pipelineDefinition) {\n        LinkedBlockingDeque linkedBlockingDeque = buildPipelineQuque(pipelineDefinition);\n        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition(ChannelPipeline.class).getBeanDefinition();\n        beanDefinition.getPropertyValues().addPropertyValue(&quot;channelHandlers&quot;,linkedBlockingDeque);\n        defaultListableBeanFactory.registerBeanDefinition(PipelineDefinition.PREFIX + pipelineDefinition.getComsumePipelineName() ,beanDefinition);\n    }\n\n    @SneakyThrows\n    private LinkedBlockingDeque buildPipelineQuque(PipelineDefinition pipelineDefinition) {\n        List&lt;String&gt; pipelineClassNames = pipelineDefinition.getPipelineClassNames();\n        if(CollectionUtil.isEmpty(pipelineClassNames)){\n           throw new PipelineException(&quot;pipelineClassNames must config&quot;);\n        }\n\n        LinkedBlockingDeque linkedBlockingDeque = new LinkedBlockingDeque();\n        for (String pipelineClassName : pipelineClassNames) {\n            Class&lt;?&gt; pipelineClassClass = Class.forName(pipelineClassName);\n            if(!AbstactChannelHandler.class.isAssignableFrom(pipelineClassClass)){\n                throw new PipelineException(&quot;pipelineClassNames must be \u3010com.github.lybgeek.pipeline.handler.AbstactChannelHandler\u3011 subclass&quot;);\n            }\n            Object pipeline = pipelineClassClass.getDeclaredConstructor().newInstance();\n            linkedBlockingDeque.addLast(pipeline);\n        }\n\n        return linkedBlockingDeque;\n    }\n\n    @Override\n    public void afterPropertiesSet() throws Exception {\n        if(CollectionUtil.isNotEmpty(pipelineDefinitionProperties.getChain())){\n            for (PipelineDefinition pipelineDefinition : pipelineDefinitionProperties.getChain()) {\n                registerPipeline(defaultListableBeanFactory, pipelineDefinition);\n            }\n        }\n    }\n\n    @Override\n    public void afterSingletonsInstantiated() {\n        Map&lt;String, ChannelPipeline&gt; pipelineBeanMap = defaultListableBeanFactory.getBeansOfType(ChannelPipeline.class);\n        pipelineBeanMap.forEach((key,bean)-&gt;{\n            bean.setHandlerContext(ChannelHandlerContext.getCurrentContext());\n        });\n\n    }\n}\n<\/code><\/pre>\n<blockquote><p>3\u3001\u7f16\u5199spring.factories<\/p><\/blockquote>\n<pre><code class=\"java\">org.springframework.boot.autoconfigure.EnableAutoConfiguration=\/\ncom.github.lybgeek.pipeline.spring.autoconfigure.PipelineAutoConfiguration\/<\/code><\/pre>\n<h3>\u4e1a\u52a1\u9879\u76ee\u5982\u4f55\u4f7f\u7528\u8be5\u65b9\u5f0f\u5b9e\u73b0\u4e1a\u52a1\u7f16\u6392<\/h3>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<blockquote><p>1\u3001\u521b\u5efa\u7ba1\u9053\u6267\u884c\u5668<\/p><\/blockquote>\n<pre><code class=\"java\">@Slf4j\npublic class UserCheckChannelHandler extends AbstactChannelHandler {\n\n    \n    @Override\n    public boolean handler(ChannelHandlerContext chx) {\n        ChannelHandlerRequest channelHandlerRequest = chx.getChannelHandlerRequest();\n        System.out.println(&quot;yml------------------------------------\u6b65\u9aa4\u4e00\uff1a\u7528\u6237\u6570\u636e\u6821\u9a8c\u3010&quot;+channelHandlerRequest.getRequestId()+&quot;\u3011&quot;);\n        Object params = channelHandlerRequest.getParams();\n        if(params instanceof User){\n            User user = (User)params;\n            if(StringUtils.isBlank(user.getFullname())){\n                log.error(&quot;\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a&quot;);\n                return false;\n            }\n            return true;\n        }\n\n\n        return false;\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"java\">@Slf4j\npublic class UserFillUsernameAndEmailChannelHandler extends AbstactChannelHandler {\n    @SneakyThrows\n    @Override\n    public boolean handler(ChannelHandlerContext chx) {\n        ChannelHandlerRequest channelHandlerRequest = chx.getChannelHandlerRequest();\n        System.out.println(&quot;yml------------------------------------\u6b65\u9aa4\u4e8c\uff1a\u7528\u6237\u540d\u4ee5\u53ca\u90ae\u7bb1\u586b\u5145\u3010\u5c06\u6c49\u8bed\u8f6c\u6210\u62fc\u97f3\u586b\u5145\u3011\u3010&quot;+channelHandlerRequest.getRequestId()+&quot;\u3011&quot;);\n        Object params = channelHandlerRequest.getParams();\n        if(params instanceof User){\n            User user = (User)params;\n            String fullname = user.getFullname();\n            HanyuPinyinOutputFormat hanyuPinyinOutputFormat = new HanyuPinyinOutputFormat();\n            hanyuPinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);\n            String username = PinyinHelper.toHanYuPinyinString(fullname, hanyuPinyinOutputFormat);\n            user.setUsername(username);\n            user.setEmail(username + &quot;@qq.com&quot;);\n            return true;\n        }\n\n\n        return false;\n    }\n}\n<\/code><\/pre>\n<p>\u3002\u3002\u3002\u5176\u4ed6\u6267\u884c\u5668\u5177\u4f53\u67e5\u770b\u94fe\u63a5\u4ee3\u7801<\/p>\n<blockquote><p>2\u3001\u914d\u7f6eyml\u6587\u4ef6<\/p><\/blockquote>\n<pre><code class=\"java\">lybgeek:\n  pipeline:\n    chain:\n      - comsumePipelineName: userYmlService\n        pipelineClassNames:\n          - com.github.lybgeek.pipeline.spring.test.yml.handler.UserCheckChannelHandler\n          - com.github.lybgeek.pipeline.spring.test.yml.handler.UserFillUsernameAndEmailChannelHandler\n          - com.github.lybgeek.pipeline.spring.test.yml.handler.UserPwdEncryptChannelHandler\n          - com.github.lybgeek.pipeline.spring.test.yml.handler.UserMockSaveChannelHandler\n          - com.github.lybgeek.pipeline.spring.test.yml.handler.UserPrintChannleHandler<\/code><\/pre>\n<blockquote><p>3\u3001\u5177\u4f53\u4e1a\u52a1service\u5f15\u5165\u7ba1\u9053bean<\/p><\/blockquote>\n<pre><code class=\"java\">@Service\npublic class UserYmlServiceImpl implements UserYmlService {\n\n\n    @Autowired\n    private ApplicationContext applicationContext;\n\n    @Override\n    public boolean save(User user) {\n\n        ChannelPipeline pipeline =  applicationContext.getBean(ChannelPipeline.class,PipelineDefinition.PREFIX + StringUtils.uncapitalize(UserYmlService.class.getSimpleName()));\n\n        return pipeline.start(ChannelHandlerRequest.builder().params(user).build());\n    }\n}<\/code><\/pre>\n<blockquote><p>4\u3001\u6d4b\u8bd5<\/p><\/blockquote>\n<pre><code class=\"java\">    @Test\n    public void testPipelineYml(){\n        boolean isOk = userYmlService.save(user);\n        Assert.assertTrue(isOk);\n\n    }\n<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042513460\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u65b9\u5f0f\u4e8c\uff1a\u5229\u7528spring\u81ea\u5b9a\u4e49\u6807\u7b7e<\/h3>\n<blockquote><p>1\u3001\u5b9a\u4e49xsd\u7ea6\u675f\u6587\u4ef6pipeline.xsd<\/p><\/blockquote>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;\n&lt;xsd:schema xmlns:xsd=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot;\n            xmlns:beans=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n            xmlns:tool=&quot;http:\/\/www.springframework.org\/schema\/tool&quot;\n            xmlns=&quot;http:\/\/lybgeek.github.com\/schema\/pipeline&quot;\n            targetNamespace=&quot;http:\/\/lybgeek.github.com\/schema\/pipeline&quot;&gt;\n\n    &lt;xsd:import namespace=&quot;http:\/\/www.w3.org\/XML\/1998\/namespace&quot;\/&gt;\n    &lt;xsd:import namespace=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n                schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&quot;\/&gt;\n    &lt;xsd:import namespace=&quot;http:\/\/www.springframework.org\/schema\/tool&quot;\/&gt;\n\n    &lt;xsd:annotation&gt;\n        &lt;xsd:documentation&gt;\n            &lt;![CDATA[ Namespace support for pipeline services ]]&gt;&lt;\/xsd:documentation&gt;\n    &lt;\/xsd:annotation&gt;\n\n\n    &lt;xsd:complexType name=&quot;pipelineType&quot;&gt;\n        &lt;xsd:choice&gt;\n            &lt;xsd:element ref=&quot;pipelineHandler&quot; minOccurs=&quot;1&quot; maxOccurs=&quot;unbounded&quot;\/&gt;\n        &lt;\/xsd:choice&gt;\n        &lt;xsd:attribute name=&quot;id&quot; type=&quot;xsd:ID&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ The unique identifier for a bean. ]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n        &lt;xsd:attribute name=&quot;consumePipelinesServiceClassName&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ consumePipelinesService class name  ]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n        &lt;xsd:attribute name=&quot;consumePipelinesMethod&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ consumePipelinesMethod name  ]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n        &lt;xsd:attribute name=&quot;argsType&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ consumePipelinesMethod args type , multiple args types are separated by commas ]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n    &lt;\/xsd:complexType&gt;\n\n    &lt;xsd:complexType name=&quot;pipelineHandlerType&quot;&gt;\n        &lt;xsd:attribute name=&quot;className&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ pipelineHanlder class name]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n        &lt;xsd:attribute name=&quot;order&quot; type=&quot;xsd:string&quot; use=&quot;required&quot;&gt;\n            &lt;xsd:annotation&gt;\n                &lt;xsd:documentation&gt;&lt;![CDATA[ pipeline class name]]&gt;&lt;\/xsd:documentation&gt;\n            &lt;\/xsd:annotation&gt;\n        &lt;\/xsd:attribute&gt;\n    &lt;\/xsd:complexType&gt;\n\n\n\n    &lt;xsd:element name=&quot;pipelineHandler&quot; type=&quot;pipelineHandlerType&quot;&gt;\n        &lt;xsd:annotation&gt;\n            &lt;xsd:documentation&gt;&lt;![CDATA[ The pipelineHandler config ]]&gt;&lt;\/xsd:documentation&gt;\n        &lt;\/xsd:annotation&gt;\n    &lt;\/xsd:element&gt;\n\n    &lt;xsd:element name=&quot;pipeline&quot; type=&quot;pipelineType&quot;&gt;\n        &lt;xsd:annotation&gt;\n            &lt;xsd:documentation&gt;&lt;![CDATA[ The pipeline config ]]&gt;&lt;\/xsd:documentation&gt;\n        &lt;\/xsd:annotation&gt;\n    &lt;\/xsd:element&gt;\n\n&lt;\/xsd:schema&gt;\n<\/code><\/pre>\n<blockquote><p>2\u3001\u914d\u7f6exsd\u7ea6\u675f\u6587\u4ef6<\/p><\/blockquote>\n<p>\u5728classpath\u4e0b\u7684resources\u6587\u4ef6\u5939\u65b0\u5efaMETA-INF\u6587\u4ef6\u5939\uff0c\u518d\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6spring.schemas\uff0c\u5185\u5bb9\u5982\u4e0b<\/p>\n<pre><code class=\"xml\">http\/:\/\/lybgeek.github.com\/schema\/pipeline\/pipeline.xsd=META-INF\/pipeline.xsd<\/code><\/pre>\n<blockquote><p>3\u3001\u5b9a\u4e49\u89e3\u6790\u81ea\u5b9a\u4e49\u6807\u7b7e\u7684\u7c7b<\/p><\/blockquote>\n<pre><code class=\"java\">public class PipelineNamespaceHandler extends NamespaceHandlerSupport {\n\n    @Override\n    public void init() {\n       registerBeanDefinitionParser(&quot;pipeline&quot;,new PipelineBeanDefinitionParser());\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"java\">public class PipelineBeanDefinitionParser implements BeanDefinitionParser {\n\n    @Override\n    public BeanDefinition parse(Element element, ParserContext parserContext) {\n        PipelineConfig pipelineConfig = buildPipelineConfig(element);\n        List&lt;HandlerInvotation&gt; handlerInvotations = this.buildHandlerInvotations(pipelineConfig);\n        GenericBeanDefinition beanDefinition = getGenericBeanDefinition(element, parserContext, pipelineConfig, handlerInvotations);\n        return beanDefinition;\n    }\n\n    private GenericBeanDefinition getGenericBeanDefinition(Element element, ParserContext parserContext, PipelineConfig pipelineConfig, List&lt;HandlerInvotation&gt; handlerInvotations) {\n        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();\n        beanDefinition.getPropertyValues().addPropertyValue(&quot;pipelineServiceClz&quot;,pipelineConfig.getConsumePipelinesService());\n        beanDefinition.getPropertyValues().addPropertyValue(&quot;handlerInvotations&quot;,handlerInvotations);\n        beanDefinition.getPropertyValues().addPropertyValue(&quot;createByXml&quot;,true);\n        beanDefinition.setBeanClass(ComsumePipelineFactoryBean.class);\n        String beanName = BeanUtils.generateBeanName(element,&quot;id&quot;,parserContext,pipelineConfig.getConsumePipelinesService().getSimpleName());\n        parserContext.getRegistry().registerBeanDefinition(beanName,beanDefinition);\n        return beanDefinition;\n    }\n\n    @SneakyThrows\n    private List&lt;HandlerInvotation&gt; buildHandlerInvotations(PipelineConfig pipelineConfig){\n        List&lt;HandlerInvotation&gt; handlerInvotations = new ArrayList&lt;&gt;();\n        for (PipelineHandlerConfig pipelineHandlerConfig : pipelineConfig.getPipelineChain()) {\n            if(!AbstactChannelHandler.class.isAssignableFrom(pipelineHandlerConfig.getPipelineClass())){\n                throw new PipelineException(&quot;pipelineHandler className must be \u3010com.github.lybgeek.pipeline.handler.AbstactChannelHandler\u3011 subclass&quot;);\n            }\n\n            AbstactChannelHandler channelHandler = (AbstactChannelHandler) pipelineHandlerConfig.getPipelineClass().getDeclaredConstructor().newInstance();\n            HandlerInvotation invotation = HandlerInvotation.builder()\n                    .args(pipelineConfig.getArgs())\n                    .handler(channelHandler)\n                    .order(pipelineHandlerConfig.getOrder())\n                    .consumePipelinesMethod(pipelineConfig.getConsumePipelinesMethod())\n                    .build();\n            handlerInvotations.add(invotation);\n\n        }\n        return handlerInvotations;\n    }\n\n    @SneakyThrows\n    private PipelineConfig buildPipelineConfig(Element element){\n        String argsType = element.getAttribute(&quot;argsType&quot;);\n        String[] argsTypeArr = trimArrayElements(commaDelimitedListToStringArray(argsType));\n        String consumePipelinesMethod = element.getAttribute(&quot;consumePipelinesMethod&quot;);\n        String consumePipelinesServiceClassName = element.getAttribute(&quot;consumePipelinesServiceClassName&quot;);\n\n\n        Class[] args = null;\n        if(ArrayUtil.isNotEmpty(argsTypeArr)){\n            args = new Class[argsTypeArr.length];\n            for (int i = 0; i &lt; argsTypeArr.length; i++) {\n                Class argType = Class.forName(argsTypeArr[i]);\n                args[i] = argType;\n            }\n        }\n\n        List&lt;PipelineHandlerConfig&gt; pipelineHandlerConfigs = buildPipelineHandlerConfig(element);\n\n        return PipelineConfig.builder().args(args)\n                .consumePipelinesMethod(consumePipelinesMethod)\n                .consumePipelinesService(Class.forName(consumePipelinesServiceClassName))\n                .pipelineChain(pipelineHandlerConfigs)\n                .build();\n    }\n\n    @SneakyThrows\n    private List&lt;PipelineHandlerConfig&gt; buildPipelineHandlerConfig(Element element){\n        NodeList nodeList = element.getChildNodes();\n        if (nodeList == null) {\n            return Collections.emptyList();\n        }\n\n        List&lt;PipelineHandlerConfig&gt; pipelineHandlerConfigs = new ArrayList&lt;&gt;();\n        for (int i = 0; i &lt; nodeList.getLength(); i++) {\n            if (!(nodeList.item(i) instanceof Element)) {\n                continue;\n            }\n            Element childElement = (Element) nodeList.item(i);\n            if (&quot;pipelineHandler&quot;.equals(childElement.getNodeName()) || &quot;pipelineHandler&quot;.equals(childElement.getLocalName())) {\n                String pipelineHanlderClassName = childElement.getAttribute(&quot;className&quot;);\n                String pipelineHanlderOrder = childElement.getAttribute(&quot;order&quot;);\n                Class pipelineHanlderClass = Class.forName(pipelineHanlderClassName);\n                PipelineHandlerConfig pipelineHandlerConfig = PipelineHandlerConfig.builder()\n                        .PipelineClass(pipelineHanlderClass)\n                        .order(Integer.valueOf(pipelineHanlderOrder))\n                        .build();\n                pipelineHandlerConfigs.add(pipelineHandlerConfig);\n            }\n        }\n\n        return pipelineHandlerConfigs;\n    }\n}\n<\/code><\/pre>\n<blockquote><p>4\u3001\u6ce8\u518c\u89e3\u6790\u7c7b<\/p><\/blockquote>\n<p>\u5728META-INF\u6587\u4ef6\u5939\u65b0\u5efaspring.handlers\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b<\/p>\n<pre><code class=\"java\">http\/:\/\/lybgeek.github.com\/schema\/pipeline=com.github.lybgeek.pipeline.spring.shema.PipelineNamespaceHandler<\/code><\/pre>\n<h3>\u4e1a\u52a1\u9879\u76ee\u5982\u4f55\u4f7f\u7528\u8be5\u65b9\u5f0f\u5b9e\u73b0\u4e1a\u52a1\u7f16\u6392<\/h3>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<blockquote><p>1\u3001\u521b\u5efa\u7ba1\u9053\u6267\u884c\u5668<\/p><\/blockquote>\n<pre><code class=\"java\">@Slf4j\npublic class UserCheckChannelHandler extends AbstactChannelHandler {\n\n    \n    @Override\n    public boolean handler(ChannelHandlerContext chx) {\n        ChannelHandlerRequest channelHandlerRequest = chx.getChannelHandlerRequest();\n        System.out.println(&quot;XML------------------------------------\u6b65\u9aa4\u4e00\uff1a\u7528\u6237\u6570\u636e\u6821\u9a8c\u3010&quot;+channelHandlerRequest.getRequestId()+&quot;\u3011&quot;);\n        String json = JSON.toJSONString(channelHandlerRequest.getParams());\n        List&lt;User&gt; users = JSON.parseArray(json,User.class);\n        if(CollectionUtil.isEmpty(users) || StringUtils.isBlank(users.get(0).getFullname())){\n            log.error(&quot;\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a&quot;);\n            return false;\n        }\n        return true;\n\n\n    }\n}\n<\/code><\/pre>\n<pre><code class=\"java\">@Slf4j\npublic class UserFillUsernameAndEmailChannelHandler extends AbstactChannelHandler {\n    @SneakyThrows\n    @Override\n    public boolean handler(ChannelHandlerContext chx) {\n        ChannelHandlerRequest channelHandlerRequest = chx.getChannelHandlerRequest();\n        System.out.println(&quot;XML------------------------------------\u6b65\u9aa4\u4e8c\uff1a\u7528\u6237\u540d\u4ee5\u53ca\u90ae\u7bb1\u586b\u5145\u3010\u5c06\u6c49\u8bed\u8f6c\u6210\u62fc\u97f3\u586b\u5145\u3011\u3010&quot;+channelHandlerRequest.getRequestId()+&quot;\u3011&quot;);\n        String json = JSON.toJSONString(channelHandlerRequest.getParams());\n        List&lt;User&gt; users = JSON.parseArray(json,User.class);\n        if(CollectionUtil.isNotEmpty(users)){\n            User user = users.get(0);\n            String fullname = user.getFullname();\n            HanyuPinyinOutputFormat hanyuPinyinOutputFormat = new HanyuPinyinOutputFormat();\n            hanyuPinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);\n            String username = PinyinHelper.toHanYuPinyinString(fullname, hanyuPinyinOutputFormat);\n            user.setUsername(username);\n            user.setEmail(username + &quot;@qq.com&quot;);\n            return true;\n\n        }\n\n\n\n        return false;\n    }\n}\n<\/code><\/pre>\n<p>\u3002\u3002\u3002\u5176\u4ed6\u6267\u884c\u5668\u5177\u4f53\u67e5\u770b\u94fe\u63a5\u4ee3\u7801<\/p>\n<blockquote><p>2\u3001\u5b9a\u4e49\u7ba1\u9053xml<\/p><\/blockquote>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n\n&lt;beans xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n       xmlns:lybgeek=&quot;http:\/\/lybgeek.github.com\/schema\/pipeline&quot;\n       xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;\n       xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-4.3.xsd\n       http:\/\/lybgeek.github.com\/schema\/pipeline http:\/\/lybgeek.github.com\/schema\/pipeline\/pipeline.xsd&quot;&gt;\n\n    \n    &lt;lybgeek:pipeline consumePipelinesServiceClassName=&quot;com.github.lybgeek.pipeline.spring.test.xml.service.UserXmlService&quot; consumePipelinesMethod=&quot;save&quot; argsType=&quot;com.github.lybgeek.pipeline.spring.test.model.User&quot;&gt;\n        &lt;lybgeek:pipelineHandler className=&quot;com.github.lybgeek.pipeline.spring.test.xml.handler.UserCheckChannelHandler&quot; order=&quot;1&quot;\/&gt;\n        &lt;lybgeek:pipelineHandler className=&quot;com.github.lybgeek.pipeline.spring.test.xml.handler.UserFillUsernameAndEmailChannelHandler&quot; order=&quot;2&quot;\/&gt;\n        &lt;lybgeek:pipelineHandler className=&quot;com.github.lybgeek.pipeline.spring.test.xml.handler.UserPwdEncryptChannelHandler&quot; order=&quot;3&quot;\/&gt;\n        &lt;lybgeek:pipelineHandler className=&quot;com.github.lybgeek.pipeline.spring.test.xml.handler.UserMockSaveChannelHandler&quot; order=&quot;4&quot;\/&gt;\n        &lt;lybgeek:pipelineHandler className=&quot;com.github.lybgeek.pipeline.spring.test.xml.handler.UserPrintChannleHandler&quot; order=&quot;5&quot;\/&gt;\n    &lt;\/lybgeek:pipeline&gt;\n<\/code><\/pre>\n<blockquote><p>3\u3001\u521b\u5efa\u4e1a\u52a1\u7ba1\u9053\u7c7b<\/p><\/blockquote>\n<pre><code class=\"java\">public interface UserXmlService {\n    boolean save(User user);\n}\n<\/code><\/pre>\n<p>\u76f4\u63a5\u5b9a\u4e49\u63a5\u53e3\u5373\u53ef<\/p>\n<blockquote><p>4\u3001\u9879\u76ee\u542f\u52a8\u7c7b\u4e0a\u52a0\u4e0a@ImportResource(&#8220;classpath:\/pipeline.xml&#8221;)<\/p><\/blockquote>\n<pre><code class=\"java\">@SpringBootApplication\n@ImportResource(&quot;classpath:\/pipeline.xml&quot;)\npublic class SpringPipelineApplication  {\n\n    public static void main(String[] args) {\n        SpringApplication.run(SpringPipelineApplication.class);\n    }\n\n\n\n}\n<\/code><\/pre>\n<blockquote><p>5\u3001\u6d4b\u8bd5<\/p><\/blockquote>\n<pre><code class=\"java\">    @Test\n    public void testPipelineXml(){\n        boolean isOk = userXmlService.save(user);\n        Assert.assertTrue(isOk);\n\n    }<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042513461\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u7684\u7ba1\u9053\u6a21\u5f0f\u7684\u6838\u5fc3\u903b\u8f91\u5185\u6838\u548c\u4e0a\u7bc7\u6587\u7ae0\u662f\u4e00\u6837\uff0c\u53ea\u662f\u628a\u7ba1\u9053\u6267\u884c\u5668\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u96c6\u4e2d\u7ba1\u7406\u8d77\u6765\uff0c\u8fd9\u4e2a\u540e\u7eed\u7ef4\u62a4\u4e5f\u6bd4\u8f83\u4e0d\u5bb9\u6613\u51fa\u9519<\/p>\n<h2>demo\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=Lsv%2BWXvOaA52G%2F8aGy0zpQ%3D%3D.uQ1b%2B7KUXMPxf4RzQmXyle32RA%2FnriOa%2FLjZIunEy0AzS06IuB6QnJFPIISpTtqwsFnd0W61YKNp5Zfo0a5rh3Bm5QYoPQuqxMgGrZsvo1Y%3D\" rel=\"nofollow\">https:\/\/github.com\/lyb-geek\/springboot-learning\/tree\/master\/springboot-pipeline<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042513458\">https:\/\/segmentfault.com\/a\/1190000042513458<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e0a\u7bc7\u6587\u7ae0\u6211\u4eec\u4ecb\u7ecd\u5229\u7528\u7ba1\u9053\u6a21\u5f0f\u6765\u8fdb\u884c\u4e1a\u52a1\u7f16\u6392\u76842\u79cd\u5b9e\u73b0\u65b9\u5f0f\u3002\u672c\u6587\u53c8\u6765\u4ecb\u7ecd\u5176\u4ed6\u5b9e\u73b0\u65b9\u5f0f \u5b9e\u73b0\u65b9\u5f0f \u65b9\u5f0f\u4e00\uff1a\u5229 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006547","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006547"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006547\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}