??xml version="1.0" encoding="utf-8" standalone="yes"?>СƱ̳-:BlogJava - 2017ϹƱ̳ͼ//www.scdqe.tw/all专注于Java技?/description>zh-cnWed, 17 Jul 2019 09:31:38 GMTWed, 17 Jul 2019 09:31:38 GMT60SPRING BATCH remote chunking模式下可同时处理多文?/title><link>//www.scdqe.tw/paulwong/archive/2019/07/16/434210.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 16 Jul 2019 06:38:00 GMT</pubDate><guid>//www.scdqe.tw/paulwong/archive/2019/07/16/434210.html</guid><wfw:comment>//www.scdqe.tw/paulwong/comments/434210.html</wfw:comment><comments>//www.scdqe.tw/paulwong/archive/2019/07/16/434210.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/paulwong/comments/commentRss/434210.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/paulwong/services/trackbacks/434210.html</trackback:ping><description><![CDATA[<div class="bld">SPRING BATCH remote chunking模式下,如果要同一时间处理多个文件,按DEMO的默认配置,是会报错的,这是由于多个文件的处理的MASTER方,是用同一个QUEUE名,这样SLAVE中处理多个JOB INSTANCE时,会返回不同的JOB-INSTANCE-ID,导致报错?br /> <br /> 这时需更改SPRING BATCH使用SPRING INTEGRATION的模式中的GATEWAY组件?br /> <br /> GATEWAY组件是工作在REQUEST/RESPONSE模式下,即发一个MESSAGE到某一QUEUE时,要从REPLY QUEUE等到CONSUMER返回结果时,才往下继续?br /> <br /> OUTBOUND GATEWAY:从某一CHANNEL获取MESSAGE,发往REQUEST QUEUE,从REPLY QUEUE等到CONSUMER返回结果,将此MESSAGE发往下一CHANNEL?br /> <br /> INBOUND GATEWAY:从某一QUEUE获取MESSAGE,发往某一REQUEST CHANNEL,从REPLY CHANNEL等到返回结果,将此MESSAGE发往下一QUEUE?br /> <br /> 详情参见此文?a target="_blank">https://blog.csdn.net/alexlau8/article/details/78056064</a>?br /> <br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> -->    <span style="color: #008000; "><!--</span><span style="color: #008000; "> Master jms </span><span style="color: #008000; ">--></span><br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int:channel </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="MasterRequestChannel"</span><span style="color: #0000FF; ">></span><br />         <span style="color: #0000FF; "><</span><span style="color: #800000; ">int:dispatcher </span><span style="color: #FF0000; ">task-executor</span><span style="color: #0000FF; ">="RequestPublishExecutor"</span><span style="color: #0000FF; ">/></span><br />     <span style="color: #0000FF; "></</span><span style="color: #800000; ">int:channel</span><span style="color: #0000FF; ">></span><br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">task:executor </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="RequestPublishExecutor"</span><span style="color: #FF0000; "> pool-size</span><span style="color: #0000FF; ">="5-10"</span><span style="color: #FF0000; "> queue-capacity</span><span style="color: #0000FF; ">="0"</span><span style="color: #0000FF; ">/></span><br /> <span style="color: #008000; "><!--</span><span style="color: #008000; ">    <int-jms:outbound-channel-adapter <br />         connection-factory="connectionFactory" <br />         destination-name="RequestQueue" <br />         channel="MasterRequestChannel"/> </span><span style="color: #008000; ">--></span><br /> <br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int:channel </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="MasterReplyChannel"</span><span style="color: #0000FF; ">/></span><br /> <span style="color: #008000; "><!--</span><span style="color: #008000; ">    <int-jms:message-driven-channel-adapter <br />         connection-factory="connectionFactory" <br />         destination-name="ReplyQueue"<br />         channel="MasterReplyChannel"/> </span><span style="color: #008000; ">--></span><br /> <br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int-jms:outbound-gateway<br />         </span><span style="color: #FF0000; ">connection-factory</span><span style="color: #0000FF; ">="connectionFactory"</span><span style="color: #FF0000; "><br />         correlation-key</span><span style="color: #0000FF; ">="JMSCorrelationID"</span><span style="color: #FF0000; "><br />         request-channel</span><span style="color: #0000FF; ">="MasterRequestChannel"</span><span style="color: #FF0000; "><br />         request-destination-name</span><span style="color: #0000FF; ">="RequestQueue"</span><span style="color: #FF0000; "><br />         receive-timeout</span><span style="color: #0000FF; ">="30000"</span><span style="color: #FF0000; "><br />         reply-channel</span><span style="color: #0000FF; ">="MasterReplyChannel"</span><span style="color: #FF0000; "><br />         reply-destination-name</span><span style="color: #0000FF; ">="ReplyQueue"</span><span style="color: #FF0000; "><br />         async</span><span style="color: #0000FF; ">="true"</span><span style="color: #0000FF; ">></span><br />         <span style="color: #0000FF; "><</span><span style="color: #800000; ">int-jms:reply-listener </span><span style="color: #0000FF; ">/></span><br />     <span style="color: #0000FF; "></</span><span style="color: #800000; ">int-jms:outbound-gateway</span><span style="color: #0000FF; ">></span><br /> <br />     <span style="color: #008000; "><!--</span><span style="color: #008000; "> Slave jms </span><span style="color: #008000; ">--></span><br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int:channel </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="SlaveRequestChannel"</span><span style="color: #0000FF; ">/></span><br /> <span style="color: #008000; "><!--</span><span style="color: #008000; ">    <int-jms:message-driven-channel-adapter<br />         connection-factory="connectionFactory" <br />         destination-name="RequestQueue"<br />         channel="SlaveRequestChannel"/> </span><span style="color: #008000; ">--></span><br /> <br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int:channel </span><span style="color: #FF0000; ">id</span><span style="color: #0000FF; ">="SlaveReplyChannel"</span><span style="color: #0000FF; ">/></span><br /> <span style="color: #008000; "><!--</span><span style="color: #008000; ">    <int-jms:outbound-channel-adapter <br />         connection-factory="connectionFactory" <br />         destination-name="ReplyQueue"<br />         channel="SlaveReplyChannel"/> </span><span style="color: #008000; ">--></span><br /> <br />     <span style="color: #0000FF; "><</span><span style="color: #800000; ">int-jms:inbound-gateway<br />         </span><span style="color: #FF0000; ">connection-factory</span><span style="color: #0000FF; ">="connectionFactory"</span><span style="color: #FF0000; "><br />         correlation-key</span><span style="color: #0000FF; ">="JMSCorrelationID"</span><span style="color: #FF0000; "><br />         request-channel</span><span style="color: #0000FF; ">="SlaveRequestChannel"</span><span style="color: #FF0000; "><br />         request-destination-name</span><span style="color: #0000FF; ">="RequestQueue"</span><span style="color: #FF0000; "><br />         reply-channel</span><span style="color: #0000FF; ">="SlaveReplyChannel"</span><span style="color: #FF0000; "><br />         default-reply-queue-name</span><span style="color: #0000FF; ">="ReplyQueue"</span><span style="color: #0000FF; ">/></span></div> </div><br /> MASTER配置<br /> <div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> //www.CodeHighlighter.com/<br /> <br /> --><span style="color: #0000FF; ">package</span> com.paul.testspringbatch.config.master;<br /> <br /> <span style="color: #0000FF; ">import</span> javax.jms.ConnectionFactory;<br /> <br /> <span style="color: #0000FF; ">import</span> org.springframework.beans.factory.config.CustomScopeConfigurer;<br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">import org.springframework.batch.core.configuration.annotation.StepScope;</span><span style="color: #008000; "><br /> </span><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Bean;<br /> <span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Configuration;<br /> <span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Profile;<br /> <span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Scope;<br /> <span style="color: #0000FF; ">import</span> org.springframework.context.support.SimpleThreadScope;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.channel.DirectChannel;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.channel.QueueChannel;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.config.EnableIntegration;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlow;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlows;<br /> <span style="color: #0000FF; ">import</span> org.springframework.integration.jms.JmsOutboundGateway;<br /> <br /> <span style="color: #0000FF; ">import</span> com.paul.testspringbatch.common.constant.IntegrationConstant;<br /> <br /> @Configuration<br /> @EnableIntegration<br /> @Profile("batch-master")<br /> <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> IntegrationMasterConfiguration {<br />     <br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">    @Value("${broker.url}")<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    private String brokerUrl;<br /> <br /> <br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    @Bean<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    public ActiveMQConnectionFactory connectionFactory() {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        connectionFactory.setBrokerURL(this.brokerUrl);<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        connectionFactory.setTrustAllPackages(true);<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        return connectionFactory;<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    }</span><span style="color: #008000; "><br /> </span><br />     <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />      * Configure outbound flow (requests going to workers)<br />      </span><span style="color: #008000; ">*/</span><br />     @Bean<br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)</span><span style="color: #008000; "><br /> </span>    <span style="color: #0000FF; ">public</span> DirectChannel requests() {<br />         <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> DirectChannel();<br />     }<br /> <br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">    @Bean<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    public IntegrationFlow outboundFlow(ConnectionFactory connectionFactory) {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        return IntegrationFlows<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .from(requests())<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .handle(Jms.outboundAdapter(connectionFactory).destination(IntegrationConstant.MASTER_REQUEST_DESTINATION))<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .get();<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    }</span><span style="color: #008000; "><br /> </span>    <br />      @Bean<br />      <span style="color: #0000FF; ">public</span> CustomScopeConfigurer customScopeConfigurer() {<br />          CustomScopeConfigurer customScopeConfigurer = <span style="color: #0000FF; ">new</span> CustomScopeConfigurer();<br />          customScopeConfigurer.addScope("thread", <span style="color: #0000FF; ">new</span> SimpleThreadScope());<br />          <span style="color: #0000FF; ">return</span> customScopeConfigurer;<br />      }<br />      <br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">     @Bean<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">     public static BeanFactoryPostProcessor beanFactoryPostProcessor() {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">         return new BeanFactoryPostProcessor() {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                <br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">             @Override<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">             public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                    beanFactory.registerScope("thread", new SimpleThreadScope());<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                }<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">              };<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">     }</span><span style="color: #008000; "><br /> </span>    <br />     <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />      * Configure inbound flow (replies coming from workers)<br />      </span><span style="color: #008000; ">*/</span><br />     @Bean<br />     @Scope(value = "thread"<span style="color: #008000; ">/*</span><span style="color: #008000; "> , proxyMode = ScopedProxyMode.NO </span><span style="color: #008000; ">*/</span>)<br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)</span><span style="color: #008000; "><br /> </span>    <span style="color: #0000FF; ">public</span> QueueChannel replies() {<br />         <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> QueueChannel();<br />     }<br /> <br /> <span style="color: #008000; ">//</span><span style="color: #008000; ">    @Bean<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    public IntegrationFlow inboundFlow(ConnectionFactory connectionFactory) {<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">        return IntegrationFlows<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .from(Jms.messageDrivenChannelAdapter(connectionFactory).destination(IntegrationConstant.MASTER_REPLY_DESTINATION))<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .channel(replies())<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .get();<br /> </span><span style="color: #008000; ">//</span><span style="color: #008000; ">    }</span><span style="color: #008000; "><br /> </span><br />     @Bean<br />     <span style="color: #0000FF; ">public</span> JmsOutboundGateway jmsOutboundGateway(ConnectionFactory connectionFactory) {<br />         JmsOutboundGateway jmsOutboundGateway = <span style="color: #0000FF; ">new</span> JmsOutboundGateway();<br />         jmsOutboundGateway.setConnectionFactory(connectionFactory);<br />         jmsOutboundGateway.setRequestDestinationName(IntegrationConstant.MASTER_REQUEST_DESTINATION);<span style="color: #008000; ">//</span><span style="color: #008000; ">2. send the message to this destination</span><span style="color: #008000; "><br /> </span>        jmsOutboundGateway.setRequiresReply(<span style="color: #0000FF; ">true</span>);<br />         jmsOutboundGateway.setCorrelationKey(IntegrationConstant.JMS_CORRELATION_KEY);<span style="color: #008000; ">//</span><span style="color: #008000; ">3. let the broker filter the message</span><span style="color: #008000; "><br /> </span>        jmsOutboundGateway.setAsync(<span style="color: #0000FF; ">true</span>);<span style="color: #008000; ">//</span><span style="color: #008000; ">must be async, so that JMS_CORRELATION_KEY work</span><span style="color: #008000; "><br /> </span>        jmsOutboundGateway.setUseReplyContainer(<span style="color: #0000FF; ">true</span>);<br />         jmsOutboundGateway.setReplyDestinationName(IntegrationConstant.MASTER_REPLY_DESTINATION);<span style="color: #008000; ">//</span><span style="color: #008000; ">4. waiting the response from this destination</span><span style="color: #008000; "><br /> </span>        jmsOutboundGateway.setReceiveTimeout(30_000);<br />         <span style="color: #0000FF; ">return</span> jmsOutboundGateway;<br />     }<br /> <br />     @Bean<br />     <span style="color: #0000FF; ">public</span> IntegrationFlow jmsOutboundGatewayFlow(ConnectionFactory connectionFactory) {<br />         <span style="color: #0000FF; ">return</span> IntegrationFlows<br />                         .from(requests())<span style="color: #008000; ">//</span><span style="color: #008000; ">1. receive message from this channel</span><span style="color: #008000; "><br /> </span>                        .handle(jmsOutboundGateway(connectionFactory))<br />                         .channel(replies())<span style="color: #008000; ">//</span><span style="color: #008000; ">5. send back the response to this channel</span><span style="color: #008000; "><br /> </span>                        .get();<br />     }<br /> <br /> }</div><br /><br />SLAVE配置?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />//www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span> com.paul.testspringbatch.config.slave;<br /><br /><span style="color: #0000FF; ">import</span> javax.jms.ConnectionFactory;<br /><br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Bean;<br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Configuration;<br /><span style="color: #0000FF; ">import</span> org.springframework.context.annotation.Profile;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.channel.DirectChannel;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.config.EnableIntegration;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlow;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.dsl.IntegrationFlows;<br /><span style="color: #0000FF; ">import</span> org.springframework.integration.jms.dsl.Jms;<br /><br /><span style="color: #0000FF; ">import</span> com.paul.testspringbatch.common.constant.IntegrationConstant;<br /><br />@Configuration<br />@EnableIntegration<br />@Profile("batch-slave")<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> IntegrationSlaveConfiguration {<br />    <br /><br />    <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />     * Configure inbound flow (requests coming from the master)<br />     </span><span style="color: #008000; ">*/</span><br />    @Bean<br />    <span style="color: #0000FF; ">public</span> DirectChannel requests() {<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> DirectChannel();<br />    }<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">    @Bean<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">    public IntegrationFlow inboundFlow(ConnectionFactory connectionFactory) {<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">        return IntegrationFlows<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .from(Jms.messageDrivenChannelAdapter(connectionFactory).destination("requests"))<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .channel(requests())<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .get();<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">    }</span><span style="color: #008000; "><br /></span><br />    <span style="color: #008000; ">/*</span><span style="color: #008000; "><br />     * Configure outbound flow (replies going to the master)<br />     </span><span style="color: #008000; ">*/</span><br />    @Bean<br />    <span style="color: #0000FF; ">public</span> DirectChannel replies() {<br />        <span style="color: #0000FF; ">return</span> <span style="color: #0000FF; ">new</span> DirectChannel();<br />    }<br /><br /><span style="color: #008000; ">//</span><span style="color: #008000; ">    @Bean<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">    public IntegrationFlow outboundFlow(ConnectionFactory connectionFactory) {<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">        return IntegrationFlows<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .from(replies())<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .handle(Jms.outboundAdapter(connectionFactory).destination("replies"))<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">                .get();<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">    }</span><span style="color: #008000; "><br /></span><br />    @Bean<br />    <span style="color: #0000FF; ">public</span> IntegrationFlow inboundGatewayFlow(ConnectionFactory connectionFactory) {<br />        <span style="color: #0000FF; ">return</span> IntegrationFlows<br />                    .from(Jms<br />                            .inboundGateway(connectionFactory)<br />                            .destination(IntegrationConstant.SLAVE_HANDLE_MASTER_REQUEST_DESTINATION)<span style="color: #008000; ">//</span><span style="color: #008000; ">1. receive message from this channel.</span><span style="color: #008000; "><br /></span>                            .correlationKey(IntegrationConstant.JMS_CORRELATION_KEY)<span style="color: #008000; ">//</span><span style="color: #008000; ">2. let the broker filter the message</span><span style="color: #008000; "><br /></span>                            .requestChannel(requests())<span style="color: #008000; ">//</span><span style="color: #008000; ">3. send the message to this channel</span><span style="color: #008000; "><br /></span>                            .replyChannel(replies())<span style="color: #008000; ">//</span><span style="color: #008000; ">4. waitting the result from this channel</span><span style="color: #008000; "><br /></span>                            .defaultReplyQueueName(IntegrationConstant.SLAVE_RETURN_RESULT_DESTINATION)<span style="color: #008000; ">//</span><span style="color: #008000; ">5.send back the result to this destination to the master.</span><span style="color: #008000; "><br /></span>                            )<br />                    .get();<br />    }<br /><br />}</div><img src ="//www.scdqe.tw/paulwong/aggbug/434210.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/paulwong/" target="_blank">paulwong</a> 2019-07-16 14:38 <a href="//www.scdqe.tw/paulwong/archive/2019/07/16/434210.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Build Messaging Between Ruby/Rails Applications with ActiveMQ - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/07/12/434156.htmlpaulwongpaulwongFri, 12 Jul 2019 09:12:00 GMT//www.scdqe.tw/paulwong/archive/2019/07/12/434156.html//www.scdqe.tw/paulwong/comments/434156.html//www.scdqe.tw/paulwong/archive/2019/07/12/434156.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/434156.html//www.scdqe.tw/paulwong/services/trackbacks/434156.htmlhttps://dev.to/kirillshevch/build-messaging-between-ruby-rails-applications-with-activemq-4fin

paulwong 2019-07-12 17:12 发表评论
]]>
微信授权登录 - 2017ϹƱ̳ͼ//www.scdqe.tw/lhbjava/archive/2019/07/12/434153.html林的林的Fri, 12 Jul 2019 05:41:00 GMT//www.scdqe.tw/lhbjava/archive/2019/07/12/434153.html//www.scdqe.tw/lhbjava/comments/434153.html//www.scdqe.tw/lhbjava/archive/2019/07/12/434153.html#Feedback0//www.scdqe.tw/lhbjava/comments/commentRss/434153.html//www.scdqe.tw/lhbjava/services/trackbacks/434153.html阅读全文

林的 2019-07-12 13:41 发表评论
]]>
STEP范围内的ROUTER - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/07/11/434137.htmlpaulwongpaulwongThu, 11 Jul 2019 03:45:00 GMT//www.scdqe.tw/paulwong/archive/2019/07/11/434137.html//www.scdqe.tw/paulwong/comments/434137.html//www.scdqe.tw/paulwong/archive/2019/07/11/434137.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/434137.html//www.scdqe.tw/paulwong/services/trackbacks/434137.html

https://gist.github.com/benas/bfe2be7386b99ce496425fac9ff35fb8

paulwong 2019-07-11 11:45 发表评论
]]>
DDD小结 - 2017ϹƱ̳ͼ//www.scdqe.tw/fool/archive/2019/07/08/434108.html? ?/dc:creator>? ?/author>Mon, 08 Jul 2019 08:49:00 GMT//www.scdqe.tw/fool/archive/2019/07/08/434108.html//www.scdqe.tw/fool/comments/434108.html//www.scdqe.tw/fool/archive/2019/07/08/434108.html#Feedback0//www.scdqe.tw/fool/comments/commentRss/434108.html//www.scdqe.tw/fool/services/trackbacks/434108.html阅读全文

]]>
solc编译问题 - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/07/08/434107.html狼爱上狸狼爱上狸Mon, 08 Jul 2019 08:11:00 GMT//www.scdqe.tw/waterjava/archive/2019/07/08/434107.html//www.scdqe.tw/waterjava/comments/434107.html//www.scdqe.tw/waterjava/archive/2019/07/08/434107.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/434107.html//www.scdqe.tw/waterjava/services/trackbacks/434107.html1.安装solc
npm install -g solc
用IDEA编译sol时出现错?br />
solcjs.cmd --abi --bin CloudNoteService.sol -o C:\Users\Administrator\IdeaProjects\test
CloudNoteService.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.10+commit.5a6ea5b1.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.22;
2.solcjs.cmd  --version//查看solc版本
0.5.10+commit.5a6ea5b1.Emscripten.clang
3.npm uninstall solc//卸载
4.npm install -g solc@0.4.24//安装solc0.4.24版本
5.C:\nodejs\node_modules\npm>solcjs.cmd --version//查看solc版本
0.4.24+commit.e67f0147.Emscripten.clang
6.solc跟web3一样,有版本的区别?/div>



狼爱上狸 2019-07-08 16:11 发表评论
]]>solidity官方开发文?/title><link>//www.scdqe.tw/waterjava/archive/2019/07/08/434106.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Mon, 08 Jul 2019 07:18:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/07/08/434106.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/434106.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/07/08/434106.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/434106.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/434106.html</trackback:ping><description><![CDATA[https://solidity-cn.readthedocs.io/zh/develop/<img src ="//www.scdqe.tw/waterjava/aggbug/434106.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-07-08 15:18 <a href="//www.scdqe.tw/waterjava/archive/2019/07/08/434106.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> u?安装 centOS 7 - 2017ϹƱ̳ͼ//www.scdqe.tw/sdyjmc/archive/2019/07/08/434104.html单飞单飞Mon, 08 Jul 2019 01:22:00 GMT//www.scdqe.tw/sdyjmc/archive/2019/07/08/434104.html//www.scdqe.tw/sdyjmc/comments/434104.html//www.scdqe.tw/sdyjmc/archive/2019/07/08/434104.html#Feedback0//www.scdqe.tw/sdyjmc/comments/commentRss/434104.html//www.scdqe.tw/sdyjmc/services/trackbacks/434104.htmlhttps://github.com/FedoraQt/MediaWriter/releases/download/4.1.4/FedoraMediaWriter-win32-4.1.4.exe

//ap.stykers.moe/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso


//ap.stykers.moe/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso


UltraISO 无法制作磁盘镜像文件,需要使用FedoraMediaWriter-win32-4.1.4 ,选择下载的iso文件,然后自定义镜像,再选U?就可以了,iso文件不能放到U盘上 U盘上的数据会都丢失?/div>


单飞 2019-07-08 09:22 发表评论
]]>
以太坊智能合?—?最佳安全开发指?/title><link>//www.scdqe.tw/waterjava/archive/2019/07/07/434094.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Sun, 07 Jul 2019 07:57:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/07/07/434094.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/434094.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/07/07/434094.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/434094.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/434094.html</trackback:ping><description><![CDATA[https://www.cnblogs.com/wanghui-garcia/p/9580573.html<img src ="//www.scdqe.tw/waterjava/aggbug/434094.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-07-07 15:57 <a href="//www.scdqe.tw/waterjava/archive/2019/07/07/434094.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CLC Genomics Workbench 12.0.2 破解 - 2017ϹƱ̳ͼ//www.scdqe.tw/galaxyp/archive/2019/07/07/434089.html舵手舵手Sun, 07 Jul 2019 04:35:00 GMT//www.scdqe.tw/galaxyp/archive/2019/07/07/434089.html//www.scdqe.tw/galaxyp/comments/434089.html//www.scdqe.tw/galaxyp/archive/2019/07/07/434089.html#Feedback0//www.scdqe.tw/galaxyp/comments/commentRss/434089.html//www.scdqe.tw/galaxyp/services/trackbacks/434089.html与N年前比,确实强了太多?br />


舵手 2019-07-07 12:35 发表评论
]]>
优秀代码赏析 - 2017ϹƱ̳ͼ//www.scdqe.tw/fool/archive/2019/07/06/434083.html? ?/dc:creator>? ?/author>Sat, 06 Jul 2019 04:06:00 GMT//www.scdqe.tw/fool/archive/2019/07/06/434083.html//www.scdqe.tw/fool/comments/434083.html//www.scdqe.tw/fool/archive/2019/07/06/434083.html#Feedback0//www.scdqe.tw/fool/comments/commentRss/434083.html//www.scdqe.tw/fool/services/trackbacks/434083.html看开源的源代码,看到一个有意思的实现 ?br />/*
 * Copyright 2019 IBM All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
package org.hyperledger.fabric.gateway;
import org.hyperledger.fabric.gateway.impl.AllCommitStrategy;
import org.hyperledger.fabric.gateway.impl.AnyCommitStrategy;
import org.hyperledger.fabric.gateway.impl.CommitHandlerImpl;
import org.hyperledger.fabric.gateway.impl.CommitStrategy;
import org.hyperledger.fabric.gateway.impl.NoOpCommitHandler;
import org.hyperledger.fabric.gateway.spi.CommitHandler;
import org.hyperledger.fabric.gateway.spi.CommitHandlerFactory;
import org.hyperledger.fabric.sdk.Peer;
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
import java.util.Collection;
/**
 * Default commit handler implementations. Instances can be referenced directly or looked up by name, for example
 * {@code DefaultCommitHandlers.valueOf("NONE")}.
 */
public enum DefaultCommitHandlers implements CommitHandlerFactory {
    /**
     * Do not wait for any commit events to be received from peers after submitting a transaction.
     */
    NONE((transactionId, network) -> NoOpCommitHandler.INSTANCE),
    /**
     * Wait to receive commit events from all currently responding peers in the user's organization after submitting
     * a transaction.
     */
    MSPID_SCOPE_ALLFORTX((transactionId, network) -> {
        Collection<Peer> peers = getPeersForOrganization(network);
        CommitStrategy strategy = new AllCommitStrategy(peers);
        CommitHandler handler = new CommitHandlerImpl(transactionId, network, strategy);
        return handler;
    }),
    /**
     * Wait to receive commit events from all currently responding peers in the network after submitting a transaction.
     */
    NETWORK_SCOPE_ALLFORTX((transactionId, network) -> {
        Collection<Peer> peers = network.getChannel().getPeers();
        CommitStrategy strategy = new AllCommitStrategy(peers);
        CommitHandler handler = new CommitHandlerImpl(transactionId, network, strategy);
        return handler;
    }),
    /**
     * Wait to receive a commit event from any currently responding peer in the user's organization after submitting
     * a transaction.
     */
    MSPID_SCOPE_ANYFORTX((transactionId, network) -> {
        Collection<Peer> peers = getPeersForOrganization(network);
        CommitStrategy strategy = new AnyCommitStrategy(peers);
        CommitHandler handler = new CommitHandlerImpl(transactionId, network, strategy);
        return handler;
    }),
    /**
     * Wait to receive a commit event from any currently responding peer in the network after submitting a transaction.
     */
    NETWORK_SCOPE_ANYFORTX((transactionId, network) -> {
        Collection<Peer> peers = network.getChannel().getPeers();
        CommitStrategy strategy = new AnyCommitStrategy(peers);
        CommitHandler handler = new CommitHandlerImpl(transactionId, network, strategy);
        return handler;
    });
    private final CommitHandlerFactory factory;
    DefaultCommitHandlers(CommitHandlerFactory factory) {
        this.factory = factory;
    }
    private static Collection<Peer> getPeersForOrganization(Network network) {
        String mspId = network.getGateway().getIdentity().getMspId();
        try {
            return network.getChannel().getPeersForOrganization(mspId);
        } catch (InvalidArgumentException e) {
            // This should never happen as mspId should not be null
            throw new RuntimeException(e);
        }
    }

   //CommitHandlerFactory 接口定义 的方法,这里是其实现 
    public CommitHandler create(String transactionId, Network network) {
        return factory.create(transactionId, network);
    }
}

先看看enum类的构造函?br />
    DefaultCommitHandlers(CommitHandlerFactory factory) {
        this.factory = factory;
    }
需要一?CommitHandlerFactory 是个接口,同?enum类本身也实现了这个接口?br />再来看调用过?nbsp;
CommitHandlerFactory commitHandlerFactory = DefaultCommitHandlers.MSPID_SCOPE_ALLFORTX;
这里会调用CommitHandlerFactory 构造函数,其传入参数是
(transactionId, network) -> {
        Collection<Peer> peers = network.getChannel().getPeers();
        CommitStrategy strategy = new AllCommitStrategy(peers);
        CommitHandler handler = new CommitHandlerImpl(transactionId, network, strategy);
        return handler;
    }
它是lamdba写法,看看构造函数需要一?nbsp;CommitHandlerFactory 接口,这个lamdba 函数其实就是CommitHandlerFactory 的实现?br />这样MSPID_SCOPE_ALLFORTX 枚举类型就有了一?nbsp; CommitHandlerFactory实现类的引用?br />
再看create调用?br />
CommitHandler commitHandler = commitHandlerFactory.create(transactionId, network);
这里enum类的create方法会执行, return factory.create(transactionId, network);
返回一?CommitHandler .这里才会真正执行那个 lamdba定义的函数?br />到这里只看到lamdb应用。。?br />再分析一下create ,枚举类里的每个枚举变量都会实现一个这个方法。这里可以看到它其实是一个工厂类?br />它创造的产品是CommitHandler ,其具体实现是CommitHandlerImpl类?br />这里巧妙的使用一个enum当工厂类的实现。整个代码用了工厂模式加策略模式的实现?br />优点:得宜于lamdb的应用,减少了具体工厂类的实现?br />缺点:工厂模式可以实现不改动程序创建产品。那么这里如果要增一个产品,对这个enum类需要再添加一个枚举变量?br />这个enum类有改动?br />



]]>
Ropsten申请测试?/title><link>//www.scdqe.tw/waterjava/archive/2019/07/05/434073.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Fri, 05 Jul 2019 13:59:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/07/05/434073.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/434073.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/07/05/434073.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/434073.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/434073.html</trackback:ping><description><![CDATA[?a target="_blank" rel="nofollow">//faucet.ropsten.be:3001/</a>上申请,只需要输入你在Ropsten网络上的账户地址就行,转币操作非常迅速,目前一次可申请1ETH?4小时后可再次申请?img src ="//www.scdqe.tw/waterjava/aggbug/434073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-07-05 21:59 <a href="//www.scdqe.tw/waterjava/archive/2019/07/05/434073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小程序技术始于微信?来看看移动端小程序技术的前世今生?/title><link>//www.scdqe.tw/jb2011/archive/2019/07/04/434043.html</link><dc:creator>Jack Jiang</dc:creator><author>Jack Jiang</author><pubDate>Thu, 04 Jul 2019 04:02:00 GMT</pubDate><guid>//www.scdqe.tw/jb2011/archive/2019/07/04/434043.html</guid><wfw:comment>//www.scdqe.tw/jb2011/comments/434043.html</wfw:comment><comments>//www.scdqe.tw/jb2011/archive/2019/07/04/434043.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/jb2011/comments/commentRss/434043.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/jb2011/services/trackbacks/434043.html</trackback:ping><description><![CDATA[     摘要: 本文由DCloud 公司创始人王安原创发布于CSDN,原题《小程序技术演进史》,即时通讯网收录时有改动,感谢原作者?、引言微信的成功,并非特定于某个具体的功能,微信的成功实际上是一大批创新技术和体验的成功合集,这也是它为何如此难此被超越的根本原因。作为微信这个超级社交应用中最为亮眼的技术之一——微信小程序,俨然已成历移动端小程序的代名词,很多人一提起“小程?...  <a href='//www.scdqe.tw/jb2011/archive/2019/07/04/434043.html'>阅读全文</a><img src ="//www.scdqe.tw/jb2011/aggbug/434043.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/jb2011/" target="_blank">Jack Jiang</a> 2019-07-04 12:02 <a href="//www.scdqe.tw/jb2011/archive/2019/07/04/434043.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>动态改变SPRING BATCH ?CHUNKSIZE - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/07/02/434011.htmlpaulwongpaulwongTue, 02 Jul 2019 03:13:00 GMT//www.scdqe.tw/paulwong/archive/2019/07/02/434011.html//www.scdqe.tw/paulwong/comments/434011.html//www.scdqe.tw/paulwong/archive/2019/07/02/434011.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/434011.html//www.scdqe.tw/paulwong/services/trackbacks/434011.htmlSPRING BATCH 读文件时,是按一行一行来读取数据,再按CHUNKSIZE提交到REMOTE操作,有时要整合当前行和下几行,再决定CHUNKSIZE,以便相关的数据能在远程同一个PROCESSOR中按顺序进行处理,因为相关的数据被拆成几个CHUNK来处理的话,就有可能不按顺序来处理。这样就需要动态调整CHUNKSIZE?br />
参照如下?br /> https://stackoverflow.com/questions/37390602/spring-batch-custom-completion-policy-for-dynamic-chunk-size

并结合SingleItemPeekableItemReader(装饰者,允许查看下一条数据,真正的操作委托给代理)?img src ="//www.scdqe.tw/paulwong/aggbug/434011.html" width = "1" height = "1" />

paulwong 2019-07-02 11:13 发表评论
]]>
史上最强Java NIO入门:担心从入门到放弃的,请读这篇! - 2017ϹƱ̳ͼ//www.scdqe.tw/jb2011/archive/2019/06/29/434008.htmlJack JiangJack JiangSat, 29 Jun 2019 14:17:00 GMT//www.scdqe.tw/jb2011/archive/2019/06/29/434008.html//www.scdqe.tw/jb2011/comments/434008.html//www.scdqe.tw/jb2011/archive/2019/06/29/434008.html#Feedback0//www.scdqe.tw/jb2011/comments/commentRss/434008.html//www.scdqe.tw/jb2011/services/trackbacks/434008.html阅读全文

Jack Jiang 2019-06-29 22:17 发表评论
]]>
web3.eth.abi - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/29/434006.html狼爱上狸狼爱上狸Sat, 29 Jun 2019 11:07:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/29/434006.html//www.scdqe.tw/waterjava/comments/434006.html//www.scdqe.tw/waterjava/archive/2019/06/29/434006.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/434006.html//www.scdqe.tw/waterjava/services/trackbacks/434006.html 1.web3?.0以下版本不支持web3.eth.abi
2.var ethabi = require('web3-eth-abi');这种引用也有问题?/div>
3.升级web3?.0以上版本后测试通过?/div>
var Web3 = require('web3');
var web3 = new Web3();

console.log(web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)'))



狼爱上狸 2019-06-29 19:07 发表评论
]]>删除无用的系统服务项 - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/29/434005.html狼爱上狸狼爱上狸Sat, 29 Jun 2019 03:41:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/29/434005.html//www.scdqe.tw/waterjava/comments/434005.html//www.scdqe.tw/waterjava/archive/2019/06/29/434005.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/434005.html//www.scdqe.tw/waterjava/services/trackbacks/434005.htmlСƱ̳-:方法?在注册表中删?/span>

运行regedit?找到
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services 中想要删除的服务?/span>

 

重启电脑可以看到你所选定的服务项在服务列表中不存在了



狼爱上狸 2019-06-29 11:41 发表评论
]]>
RABBITMQ资源 - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/06/28/434001.htmlpaulwongpaulwongFri, 28 Jun 2019 02:24:00 GMT//www.scdqe.tw/paulwong/archive/2019/06/28/434001.html//www.scdqe.tw/paulwong/comments/434001.html//www.scdqe.tw/paulwong/archive/2019/06/28/434001.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/434001.html//www.scdqe.tw/paulwong/services/trackbacks/434001.htmlhttps://www.jianshu.com/p/79ca08116d57

Spring Boot 中使?RabbitMQ
https://juejin.im/post/59f194e06fb9a0451329ec53






paulwong 2019-06-28 10:24 发表评论
]]>
infura的使?/title><link>//www.scdqe.tw/waterjava/archive/2019/06/27/433997.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Thu, 27 Jun 2019 14:45:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/06/27/433997.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/433997.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/06/27/433997.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/433997.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/433997.html</trackback:ping><description><![CDATA[https://chaindesk.cn/witbook/1/12<img src ="//www.scdqe.tw/waterjava/aggbug/433997.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-06-27 22:45 <a href="//www.scdqe.tw/waterjava/archive/2019/06/27/433997.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sol在线测试 - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/27/433994.html狼爱上狸狼爱上狸Thu, 27 Jun 2019 13:00:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/27/433994.html//www.scdqe.tw/waterjava/comments/433994.html//www.scdqe.tw/waterjava/archive/2019/06/27/433994.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/433994.html//www.scdqe.tw/waterjava/services/trackbacks/433994.html

狼爱上狸 2019-06-27 21:00 发表评论
]]>
一个DDD示例代码 - 2017ϹƱ̳ͼ//www.scdqe.tw/fool/archive/2019/06/27/433990.html? ?/dc:creator>? ?/author>Thu, 27 Jun 2019 09:09:00 GMT//www.scdqe.tw/fool/archive/2019/06/27/433990.html//www.scdqe.tw/fool/comments/433990.html//www.scdqe.tw/fool/archive/2019/06/27/433990.html#Feedback0//www.scdqe.tw/fool/comments/commentRss/433990.html//www.scdqe.tw/fool/services/trackbacks/433990.htmlgithub上的一个java版的DDD实现的示例代? 学习DDD时看一下还是不错的?br />https://github.com/daoqidelv/community-ddd-demo.git
作者不是俺?/div>

]]>
How to implement JMS ReplyTo using SpringBoot - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/06/27/433981.htmlpaulwongpaulwongThu, 27 Jun 2019 01:20:00 GMT//www.scdqe.tw/paulwong/archive/2019/06/27/433981.html//www.scdqe.tw/paulwong/comments/433981.html//www.scdqe.tw/paulwong/archive/2019/06/27/433981.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/433981.html//www.scdqe.tw/paulwong/services/trackbacks/433981.html

Request-Response is a message-exchange-pattern. In some cases, a message producer may want the consumers to reply to a message. The JMSReplyTo header indicates which destination, if any, a JMS consumer should reply to. The JMSReplyTo header is set explicitly by the JMS client; its contents will be a javax.jms.Destination object (either Topic or Queue).

In some cases, the JMS client will want the message consumers to reply to a temporary topic or queue set up by the JMS client. When a JMS message consumer receives a message that includes a JMSReplyTo destination, it can reply using that destination. A JMS consumer is not required to send a reply, but in some JMS applications, clients are programmed to do so.

For simplicity, this pattern is typically implemented in a purely synchronous fashion, as in web service calls over HTTP, which holds a connection open and waits until the response is delivered or the timeout period expires. However, request–response may also be implemented asynchronously, with a response being returned at some unknown later time.

For more information, check here.

Now, let’s jump into the code. In Spring, there are 2 ways to implement this (at least I know of).

  1. Using JMSTemplate
  2. Using Spring Integration

For demo purpose, I used ActiveMQ. However, you can implement this in other messaging systems like IBM MQ, Rabbit MQ, Tibco EMS, etc. In this demo, I send an ObjectMessage of type Order and reply with a Shipment object.

Using JMSTemplate

  1. First, we include the required dependencies. Replace the activemq dependency with your messaging system’s jars if not using ActiveMQ

     <dependencies>
         
    <dependency>
             
    <groupId>org.springframework.boot</groupId>
             
    <artifactId>spring-boot-starter-activemq</artifactId>
         
    </dependency>
         
    <dependency>
             
    <groupId>org.apache.activemq.tooling</groupId>
             
    <artifactId>activemq-junit</artifactId>
             
    <version>${activemq.version}</version>
             
    <scope>test</scope>
         
    </dependency>
         
    <dependency>
             
    <groupId>org.springframework.boot</groupId>
             
    <artifactId>spring-boot-starter-test</artifactId>
             
    <scope>test</scope>
         
    </dependency>
     
    </dependencies>
  2. Using the default spring.activemq. properties to configure the application with the ActiveMQ. However, you can do this inside a @Configuration class as well.

     spring:
       activemq:
         broker-url: tcp://localhost:
    61616
         non-blocking-redelivery: true
         packages:
           trust-all: true    
  3. Note in the above configuration spring.activemq.packages.trust-all can be changed to spring.activemq.packages.trusted with the appropriate packages.
  4. Now spring will do it’s magic and inject all the required Beans as usual :) However, in our code, we need to EnableJms

    import org.springframework.context.annotation.Configuration;
     
    import org.springframework.jms.annotation.EnableJms;

     @EnableJms
     @Configuration
     
    public class ActiveMQConfig {

         
    public static final String ORDER_QUEUE = "order-queue";
         
    public static final String ORDER_REPLY_2_QUEUE = "order-reply-2-queue";

     }
  5. First, we will configure the Producer

     @Slf4j
     @Service
     
    public class Producer {

         @Autowired
         JmsMessagingTemplate jmsMessagingTemplate;

         @Autowired
         JmsTemplate jmsTemplate;

         
    public Shipment sendWithReply(Order order) throws JMSException {
             jmsTemplate.setReceiveTimeout(
    1000L);
             jmsMessagingTemplate.setJmsTemplate(jmsTemplate);

             Session session 
    = jmsMessagingTemplate.getConnectionFactory().createConnection()
                     .createSession(
    false, Session.AUTO_ACKNOWLEDGE);

             ObjectMessage objectMessage 
    = session.createObjectMessage(order);

             objectMessage.setJMSCorrelationID(UUID.randomUUID().toString());
             objectMessage.setJMSReplyTo(
    new ActiveMQQueue(ORDER_REPLY_2_QUEUE));
             objectMessage.setJMSCorrelationID(UUID.randomUUID().toString());
             objectMessage.setJMSExpiration(
    1000L);
             objectMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);

             
    return jmsMessagingTemplate.convertSendAndReceive(new ActiveMQQueue(ORDER_QUEUE),
                     objectMessage, Shipment.
    class); //this operation seems to be blocking + sync
         }
     }
  6. Note in the above code that, JmsMessagingTemplate is used instead of JmsTemplatebecause, we are interested in the method convertSendAndReceive. As seen in the method signature, it waits to receive the Shipment object from the consumer.
  7. Next, we can see the Receiver

     @Component
     
    public class Receiver implements SessionAwareMessageListener<Message> {

         @Override
         @JmsListener(destination 
    = ORDER_QUEUE)
         
    public void onMessage(Message message, Session session) throws JMSException {
             Order order 
    = (Order) ((ActiveMQObjectMessage) message).getObject();
             Shipment shipment 
    = new Shipment(order.getId(), UUID.randomUUID().toString());

             
    // done handling the request, now create a response message
             final ObjectMessage responseMessage = new ActiveMQObjectMessage();
             responseMessage.setJMSCorrelationID(message.getJMSCorrelationID());
             responseMessage.setObject(shipment);

             
    // Message sent back to the replyTo address of the income message.
             final MessageProducer producer = session.createProducer(message.getJMSReplyTo());
             producer.send(responseMessage);
         }
     }
  8. Using the javax.jms.Session the javax.jms.MessageProducer is created and used to send the reply message to the JMSReplyTo queue. In real life, this receiver could be a different application altogether.

Using Spring Integration

  1. First, we include the required dependencies in addition to the above dependencies

     <dependency>
       
    <groupId>org.springframework.integration</groupId>
       
    <artifactId>spring-integration-jms</artifactId>
     
    </dependency>
  2. Using the default spring.activemq. properties to configure the application with the ActiveMQ. However, you can do this inside a @Configuration class as well.

     spring:
       activemq
    :
         broker
    -url: tcp://localhost:61616
         non
    -blocking-redelivery: true
         packages
    :
           trust
    -all: true   
  3. Note in the above configuration spring.activemq.packages.trust-all can be changed to spring.activemq.packages.trusted with the appropriate packages.
  4. Next we create the required Beans for the Spring Integration.

     @EnableIntegration
     @IntegrationComponentScan
     @Configuration
     
    public class ActiveMQConfig {

         
    public static final String ORDER_QUEUE = "order-queue";
         
    public static final String ORDER_REPLY_2_QUEUE = "order-reply-2-queue";

         @Bean
         
    public MessageConverter messageConverter() {
             MappingJackson2MessageConverter converter 
    = new MappingJackson2MessageConverter();
             converter.setTargetType(MessageType.TEXT);
             converter.setTypeIdPropertyName(
    "_type");
             
    return converter;
         }

         @Bean
         
    public MessageChannel requests() {
             
    return new DirectChannel();
         }

         @Bean
         @ServiceActivator(inputChannel 
    = "requests")
         
    public JmsOutboundGateway jmsGateway(ActiveMQConnectionFactory activeMQConnectionFactory) {
             JmsOutboundGateway gateway 
    = new JmsOutboundGateway();
             gateway.setConnectionFactory(activeMQConnectionFactory);
             gateway.setRequestDestinationName(ORDER_QUEUE);
             gateway.setReplyDestinationName(ORDER_REPLY_2_QUEUE);
             gateway.setCorrelationKey(
    "JMSCorrelationID");
             gateway.setSendTimeout(
    100L);
             gateway.setReceiveTimeout(
    100L);
             
    return gateway;
         }

         @Autowired
         Receiver receiver;

         @Bean
         
    public DefaultMessageListenerContainer responder(ActiveMQConnectionFactory activeMQConnectionFactory) {
             DefaultMessageListenerContainer container 
    = new DefaultMessageListenerContainer();
             container.setConnectionFactory(activeMQConnectionFactory);
             container.setDestinationName(ORDER_QUEUE);
             MessageListenerAdapter adapter 
    = new MessageListenerAdapter(new Object() {

                 @SuppressWarnings(
    "unused")
                 
    public Shipment handleMessage(Order order) {
                     
    return receiver.receiveMessage(order);
                 }

             });
             container.setMessageListener(adapter);
             
    return container;
         }
     }
  5. Next, we will configure the MessagingGateway

     @MessagingGateway(defaultRequestChannel = "requests")
     
    public interface ClientGateway {
         Shipment sendAndReceive(Order order);
     }
  6. We then Autowire this gateway in our Component class when we want to send and receive the message. A sample is shown below.

     @Slf4j
     @Component
     
    public class Receiver {
         
    public Shipment receiveMessage(@Payload Order order) {
             Shipment shipment 
    = new Shipment(order.getId(), UUID.randomUUID().toString());
             
    return shipment;
         }
     }
  7. Next we configure the Componen to process the Order message. After successful execution, this component will send the Shipment message to the JMSReplyTo queue. In real life, this receiver could be a different application altogether.

For those, who just want to clone the code, head out to aniruthmp/jms



paulwong 2019-06-27 09:20 发表评论
]]>ACTIVE MQ高级特?/title><link>//www.scdqe.tw/paulwong/archive/2019/06/26/433972.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 26 Jun 2019 06:13:00 GMT</pubDate><guid>//www.scdqe.tw/paulwong/archive/2019/06/26/433972.html</guid><wfw:comment>//www.scdqe.tw/paulwong/comments/433972.html</wfw:comment><comments>//www.scdqe.tw/paulwong/archive/2019/06/26/433972.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/paulwong/comments/commentRss/433972.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/paulwong/services/trackbacks/433972.html</trackback:ping><description><![CDATA[<a target="_blank">https://blog.51cto.com/1754966750/category17.html</a><br /><img src ="//www.scdqe.tw/paulwong/aggbug/433972.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/paulwong/" target="_blank">paulwong</a> 2019-06-26 14:13 <a href="//www.scdqe.tw/paulwong/archive/2019/06/26/433972.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ipfs和eth结合的例?/title><link>//www.scdqe.tw/waterjava/archive/2019/06/26/433969.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 26 Jun 2019 00:21:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/06/26/433969.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/433969.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/06/26/433969.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/433969.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/433969.html</trackback:ping><description><![CDATA[https://github.com/tooploox/ipfs-eth-database<img src ="//www.scdqe.tw/waterjava/aggbug/433969.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-06-26 08:21 <a href="//www.scdqe.tw/waterjava/archive/2019/06/26/433969.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 少啰嗦!一分钟带你读懂Java的NIO和经典IO的区?/title><link>//www.scdqe.tw/jb2011/archive/2019/06/25/433956.html</link><dc:creator>Jack Jiang</dc:creator><author>Jack Jiang</author><pubDate>Tue, 25 Jun 2019 08:32:00 GMT</pubDate><guid>//www.scdqe.tw/jb2011/archive/2019/06/25/433956.html</guid><wfw:comment>//www.scdqe.tw/jb2011/comments/433956.html</wfw:comment><comments>//www.scdqe.tw/jb2011/archive/2019/06/25/433956.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/jb2011/comments/commentRss/433956.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/jb2011/services/trackbacks/433956.html</trackback:ping><description><![CDATA[<h1 class="bld">1、引言</h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">很多初涉网络编程的程序员,在研究Java NIO(即异步IO)和经典IO(也就是常说的阻塞式IO)的API时,很快就会发现一个问题:我什么时候应该使用经典IO,什么时候应该使用NIO?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">在本文中,将尝试用简明扼要的文字,阐明Java NIO和经典IO之间的差异、典型用例,以及这些差异如何影响我们的网络编程或数据传输代码的设计和实现的?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">本文没有复杂理论,也没有像网上基它文章一样千篇一律的复制粘贴,有的只是接地气的通俗易懂,希望能给你带来帮助?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="color: #000000; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">(本文同步发布于?/span><a target="_blank" data-mce- style="font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">//www.52im.net/thread-2635-1-1.html</a><span style="color: #000000; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">?/span></p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 600px; max-height: 338px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 337.969px;"></div><div data-width="600" data-height="338" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 600px; height: 337.969px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-ebba96b917fb0245.jpeg" src="//upload-images.jianshu.io/upload_images/1500839-ebba96b917fb0245.jpeg" data-original-width="600" data-original-height="338" data-original-format="image/jpeg" data-original-filesize="21908" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><h1 class="bld">2、相关文?/h1><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;"></p><ul style="overflow-wrap: break-word; margin: 0px; padding: 0px; border: 0px; vertical-align: baseline; font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif, "Microsoft Yahei"; font-size: 15px; background-color: #ffffff;"><li style="overflow-wrap: break-word; margin: 0px 0px 5px 2em; padding: 0px; list-style: disc; font-size: 14px; color: #666666;">?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Java新一代网络编程模型AIO原理及Linux系统AIO介绍</a>?/li><li style="overflow-wrap: break-word; margin: 0px 0px 5px 2em; padding: 0px; list-style: disc; font-size: 14px; color: #666666;">?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Java NIO基础视频教程、MINA视频教程、Netty快速入门视?[网盘下载]</a>?/li></ul><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;"></p></blockquote><h1 class="bld">3、Java NIO和IO的主要区?/h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">下表总结了Java NIO和IO之间的主要区别。我将在表格后面的部分中详细介绍每个区别?/p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 700px; max-height: 167px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 142.234px;"></div><div data-width="822" data-height="167" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 700px; height: 142.234px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-ee0a0dbe7ba00d41.jpg" src="//upload-images.jianshu.io/upload_images/1500839-ee0a0dbe7ba00d41.jpg" data-original-width="822" data-original-height="167" data-original-format="image/jpeg" data-original-filesize="17001" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><h4>3.1 Stream Oriented vs. Buffer Oriented</h4><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">Java NIO和IO之间的第一个重要区别是IO是面向流的,其中NIO是面向缓冲区的。那么,这意味着什么?</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">面向流的Java IO意味着您可以从流中一次读取一个或多个字节。你对读取的字节做什么取决于你。它们不会缓存在任何地方。此外,您无法在流中的数据中前后移动。如果需要在从流中读取的数据中前后移动,则需要先将其缓存在缓冲区中?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">Java NIO的面向缓冲区的方法略有不同。数据被读入缓冲区,稍后处理该缓冲区。你可以根据需要在缓冲区中前后移动。这使你在处理过程中具有更大的灵活性。但是,你还需要检查缓冲区是否包含完整处理所需的所有数据。并且,你需要确保在将更多数据读入缓冲区时,不要覆盖尚未处理的缓冲区中的数据?/p><h4>3.2 Blocking vs. Non-blocking IO</h4><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">Java IO的各种流都是blocking的。这意味着,当线程调用read()或write()时,该线程将被阻塞,直到有一些数据要读取,或者数据被完全写入,在此期间,该线程无法执行任何其他操作?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">Java NIO的非阻塞模式允许线程请求从通道读取数据,并且只获取当前可用的内容,或者根本没有数据,如果当前没有数据可用。线程可以继续使用其他内容,而不是在数据可供读取之前保持阻塞状态?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">非阻塞写入也是如此,线程可以请求将某些数据写入通道,但不要等待它完全写入。然后线程可以继续并在同一时间做其他事情?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">线程在IO调用中没有阻塞时花费空闲时间,通常在此期间在其他通道上执行IO。也就是说,单个线程现在可以管理多个输入和输出通道?/p><h1 class="bld">4、Selectors</h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">Java NIO的选择器允许单个线程监视多个输入通道。你可以使用选择器注册多个通道,然后使用单个线?#8220;选择”具有可用于处理的输入的通道,或者选择准备写入的通道。这种选择器机制使单个线程可以轻松管理多个通道?/p><h1 class="bld">5、NIO和经典IO如何影响应用程序的设计?</h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">选择NIO或IO作为IO工具包可能会影响应用程序设计的以下方?</span></p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">1)API调用NIO或IO类;</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">2)处理数据;</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">3)用于处理数据的线程数?/p><h4>5.1 API调用</h4><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">当然,使用NIO时的API调用看起来与使用IO时不同。这并不奇怪。而不是仅仅从例如InputStream读取字节的数据字节,必须首先将数据读入缓冲区,然后从那里进行处理?/p><h4>5.2 数据处理</h4><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">使用纯NIO设计与IO设计时,数据处理也会受到影响?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">在IO设计中,您从InputStream或Reader中读取字节的数据字节。想象一下,您正在处理基于行的文本数据流?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">例如?/span></p><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">Name: Anna</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">Age: 25</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">Email: [url=mailto:anna@mailserver.com]anna@mailserver.com[/url]</p><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;">Phone: 1234567890</p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">这个文本行流可以像这样处理:</span></p><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">InputStream input = ... ; // get the InputStream from the client socket</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;"><br style="box-sizing: border-box;" /></p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">BufferedReader reader = newBufferedReader(newInputStreamReader(input));</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;"><br style="box-sizing: border-box;" /></p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">String nameLine   = reader.readLine();</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">String ageLine    = reader.readLine();</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">String emailLine  = reader.readLine();</p><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;">String phoneLine  = reader.readLine();</p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">注意处理状态是如何,由程序执行的程度决定的。换句话说,一旦第一个reader.readLine()方法返回,您就确定已经读取了整行文本。readLine()会阻塞直到读取整行,这就是原因。您还知道此行包含名称。同样,当第二个readLine()调用返回时,您知道此行包含年龄等?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">正如您所看到的,只有当有新数据要读取时,程序才会进行,并且对于每个步骤,您都知道该数据是什么。一旦执行的线程已经超过读取代码中的某个数据片段,该线程就不会在数据中向后移动(通常不会)?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">此图中还说明了此原则?/span></p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 342px; max-height: 326px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 325.984px;"></div><div data-width="342" data-height="326" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 342px; height: 325.984px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-ccb5dfcd37ebdb45.jpg" src="//upload-images.jianshu.io/upload_images/1500839-ccb5dfcd37ebdb45.jpg" data-original-width="342" data-original-height="326" data-original-format="image/jpeg" data-original-filesize="14514" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">▲ Java IO:从阻塞流中读取数据</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">NIO的实现看起来会有所不同,这是一个简化的例子?/span></p><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">ByteBuffer buffer = ByteBuffer.allocate(48);</p><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;">intbytesRead = inChannel.read(buffer);</p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">注意第二行从通道读取字节到ByteBuffer。当该方法调用返回时,您不知道所需的所有数据是否都在缓冲区内。你只知道缓冲区包含一些字节,这使得处理更加困难?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">想象一下,在第一次读取(缓冲)调用之后,是否所有读入缓冲区的内容都是半行。例如,“姓名:An”。你能处理这些数据吗?并不是的。在完成任何数据的处理之前,您需要等待至少一整行数据进入缓冲区?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">那么你怎么知道缓冲区是否包含足够的数据来处理它?好吧,你没有。找出的唯一方法是查看缓冲区中的数据。结果是,在您知道所有数据是否存在之前,您可能需要多次检查缓冲区中的数据。这既低效又可能在程序设计方面变得混乱?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">例如?/span></p><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">ByteBuffer buffer = ByteBuffer.allocate(48);</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">intbytesRead = inChannel.read(buffer);</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">while(! bufferFull(bytesRead) ) {</p><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">    bytesRead = inChannel.read(buffer);</p><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;">}</p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">bufferFull()方法必须跟踪读入缓冲区的数据量,并返回true或false,具体取决于缓冲区是否已满。换句话说,如果缓冲区已准备好进行处理,则认为它已满?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">bufferFull()方法扫描缓冲区,但必须使缓冲区保持与调用bufferFull()方法之前相同的状态。如果不是,则可能无法在正确的位置读入读入缓冲区的下一个数据。这不是不可能的,但这是另一个需要注意的问题?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">如果缓冲区已满,则可以对其进行处理。如果它不满,您可能能够部分处理那里的任何数据,如果这在您的特定情况下是有意义的。在许多情况下,它没有?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">这个图中说明了is-data-in-buffer-ready循环?/span></p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 421px; max-height: 297px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 297px;"></div><div data-width="421" data-height="297" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 421px; height: 297px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-3abb8d1933581759.jpg" src="//upload-images.jianshu.io/upload_images/1500839-3abb8d1933581759.jpg" data-original-width="421" data-original-height="297" data-original-format="image/jpeg" data-original-filesize="15497" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">▲ Java NIO:从通道读取数据,直到所有需要的数据都在缓冲区中</p><h1 class="bld">6、什么时候该用NIO?什么时候该用经典IO?/h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">NIO允许您仅使用一个(或几个)线程来管理多个通道(网络连接或文件),但成本是解析数据可能比从阻塞流中读取数据时更复杂?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">如果您需要同时管理数千个打开的连接,每个只发送一些数据,例如聊天服务器,在NIO中实现服务器可能是一个优势。同样,如果您需要与其他计算机保持大量开放连接,例如在P2P网络中,使用单个线程来管理所有出站连接可能是一个优势?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">此图中说明了这一个线程,多个连接设计?/span></p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 293px; max-height: 252px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 252px;"></div><div data-width="293" data-height="252" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 293px; height: 252px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-e4fae4fb9dbb5896.jpg" src="//upload-images.jianshu.io/upload_images/1500839-e4fae4fb9dbb5896.jpg" data-original-width="293" data-original-height="252" data-original-format="image/jpeg" data-original-filesize="11133" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">▲ Java NIO:管理多个连接的单个线程</p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">如果您拥有较少带宽的连接,一次发送大量数据,那么可能最经典的IO服务器实现可能是最合适的?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">此图说明了经典的IO服务器设计:</span></p><div style="box-sizing: border-box; padding-bottom: 25px; width: 700px; margin-left: -40px; text-align: center; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff;"><div style="box-sizing: border-box; position: relative; z-index: 100; background-color: transparent; transition: background-color 0.1s linear 0s; margin: 0px auto; max-width: 500px; max-height: 235px;"><div style="box-sizing: border-box; z-index: 50; padding-bottom: 235px;"></div><div data-width="500" data-height="235" style="box-sizing: border-box; position: absolute; top: 0px; left: 0px; width: 500px; height: 235px; overflow: hidden;"><img data-original-src="//upload-images.jianshu.io/upload_images/1500839-230f65397a072783.jpg" src="//upload-images.jianshu.io/upload_images/1500839-230f65397a072783.jpg" data-original-width="500" data-original-height="235" data-original-format="image/jpeg" data-original-filesize="18859" style="box-sizing: border-box; border: 0px; vertical-align: middle; transition: all 0.15s linear 0s; z-index: 100; opacity: 1; max-width: 100%; height: auto; cursor: zoom-in; display: block; filter: blur(0px);" alt="" /></div></div></div><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">▲ Java IO:经典的IO服务器设?- 由一个线程处理的一个连?/p><h1 class="bld">7、更简化的理解</h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">以众所周之的数据读取过程为例,我们来一个更简化的理解?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">对于数据读取,就读取速度来说:CPU > 内存 > 硬盘?/p><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;">I- 就是从硬盘到内存</p><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;">O- 就是从内存到硬盘</p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">第一种方式:</span>从硬盘读取数据,然后程序一直等,数据读完后,继续你的操作。这种方式是最简单的,叫阻塞IO(也就是经典IO)?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="box-sizing: border-box; font-weight: 700;">第二种方式:</span>从硬盘读取数据,然后程序继续向下执行,等数据读取完后,通知当前程序读取完成(对硬件来说叫中断,对程序来说叫回调),然后此程序可以立即处理读取的数据,也可以执行完当前操作后再对读取完的数据进行操作?/p><h1 class="bld">8、总而言?/h1><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">还是以数据读取为例,操作系统是按块Block(块)从硬盘拿数据,就如同一个大脸盆,一下子就放入了一盆水。但是,?Java 使用的时候,旧的 IO(经典IO)确实基??Stream的,也就是虽然操作系统给我了一脸盆水,但是我得用吸管慢慢喝?/p><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;">由于经典IO的重重落后理念,于是,NIO 横空出世。。?/p><h1 class="bld">附录:更多NIO异步网络编程资料</h1><blockquote style="box-sizing: border-box; padding: 20px; margin: 0px 0px 25px; font-size: 16px; border-left-width: 6px; border-left-color: #b4b4b4; background-color: #f7f7f7; line-height: 30px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; word-break: break-word !important;"><p style="box-sizing: border-box; margin: 0px 0px 25px; line-height: 1.7; word-break: break-word !important;"></p><table cellspacing="0" cellpadding="0" style="overflow-wrap: break-word; empty-cells: show; border-collapse: collapse; table-layout: fixed; width: 944px; color: #2f2f2f; font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif, "Microsoft Yahei"; font-size: 12px; background-color: #ffffff;"><tbody style="overflow-wrap: break-word;"><tr style="overflow-wrap: break-word;"><td id="postmessage_13006" style="overflow-wrap: break-word; font-size: 15px;">?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Java新一代网络编程模型AIO原理及Linux系统AIO介绍</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">有关“为何选择Netty”?1个疑问及解答</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">开源NIO框架八卦——到底是先有MINA还是先有Netty?</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">选Netty还是Mina:深入研究与对比(一?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">选Netty还是Mina:深入研究与对比(二?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">NIO框架入门(一):服务端基于Netty4的UDP双向通信Demo演示</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">NIO框架入门(?:服务端基于MINA2的UDP双向通信Demo演示</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">NIO框架入门(?:iOS与MINA2、Netty4的跨平台UDP双向通信实战</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">NIO框架入门(?:Android与MINA2、Netty4的跨平台UDP双向通信实战</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Netty 4.x学习(一):ByteBuf详解</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Netty 4.x学习(二):Channel和Pipeline详解</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Netty 4.x学习(三):线程模型详解</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Apache Mina框架高级篇(一):IoFilter详解</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Apache Mina框架高级篇(二):IoHandler详解</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">MINA2 线程原理总结(含简单测试实例)</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Apache MINA2.0 开发指南(中文版)[附件下载]</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">MINA、Netty的源代码(在线阅读版)已整理发布</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">解决MINA数据传输中TCP的粘包、缺包问题(有源码)</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">解决Mina中多个同类型Filter实例共存的问?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">实践总结:Netty3.x升级Netty4.x遇到的那些坑(线程篇?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">实践总结:Netty3.x VS Netty4.x的线程模?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">详解Netty的安全性:原理介绍、代码演示(上篇?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">详解Netty的安全性:原理介绍、代码演示(下篇?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">详解Netty的优雅退出机制和原理</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">NIO框架详解:Netty的高性能之道</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Twitter:如何使用Netty 4来减少JVM的GC开销(译文)</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">绝对干货:基于Netty实现海量接入的推送服务技术要?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">Netty干货分享:京东京麦的生产级TCP网关技术实践总结</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">新手入门:目前为止最透彻的的Netty高性能原理和框架架构解?/a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">写给初学者:Java高性能NIO框架Netty的学习方法和进阶策略</a>?br style="overflow-wrap: break-word;" />?a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">少啰嗦!一分钟带你读懂Java的NIO和经典IO的区?/a>?br style="overflow-wrap: break-word;" />>> <a target="_blank" style="overflow-wrap: break-word; color: #0078b6; text-decoration-line: none; transition: all 0.3s ease 0s;">更多同类文章 ……</a></td></tr><tr style="overflow-wrap: break-word;"><td style="overflow-wrap: break-word;"></td></tr></tbody></table><p style="box-sizing: border-box; margin: 0px; line-height: 1.7; word-break: break-word !important;"><a target="_blank" style="box-sizing: border-box; background-color: transparent; color: #3194d0; text-decoration-line: none; cursor: pointer;"></a></p></blockquote><p style="box-sizing: border-box; margin: 0px 0px 25px; color: #2f2f2f; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 16px; background-color: #ffffff; word-break: break-word !important;"><span style="color: #000000; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">(本文同步发布于?/span><a target="_blank" data-mce- style="font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">//www.52im.net/thread-2635-1-1.html</a><span style="color: #000000; font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">?/span></p><img src ="//www.scdqe.tw/jb2011/aggbug/433956.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/jb2011/" target="_blank">Jack Jiang</a> 2019-06-25 16:32 <a href="//www.scdqe.tw/jb2011/archive/2019/06/25/433956.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>第十一?从宠物商店案例看DAPP架构和WEB3.JS交互接口 - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/25/433951.html狼爱上狸狼爱上狸Tue, 25 Jun 2019 03:05:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/25/433951.html//www.scdqe.tw/waterjava/comments/433951.html//www.scdqe.tw/waterjava/archive/2019/06/25/433951.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/433951.html//www.scdqe.tw/waterjava/services/trackbacks/433951.html

狼爱上狸 2019-06-25 11:05 发表评论
]]>
truffle里的solc版本与实际solc版本冲突的问?/title><link>//www.scdqe.tw/waterjava/archive/2019/06/25/433949.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Tue, 25 Jun 2019 01:05:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/06/25/433949.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/433949.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/06/25/433949.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/433949.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/433949.html</trackback:ping><description><![CDATA[<div class="bld"> 1.因为solc@0.5.1出现调用简单运算合约出现返?的问题,所以把solc降到?.4.22?/div><div class="bld">2.安装truffle后,npm install -g truffle,版本有所不同?/div><div class="bld">PS C:\> truffle version<br />Truffle v5.0.24 (core: 5.0.24)<br />Solidity v0.5.0 (solc-js)<br />Node v10.16.0<br />Web3.js v1.0.0-beta.37</div><div class="bld">3.建立简单合约Greeter.sol后,利用truffle compile后,出现?/div><div class="bld">Error: CompileError: ParsedContract.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.8+commit.23d335f2.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version<br />pragma solidity ^0.4.24;<br />^----------------------^<br /><br />Compilation failed. See above.</div><div class="bld">4.修改truffle-config.js文件?/div><div class="bld"><pre style="background-color:#ffffff;color:#000000;font-family:'宋体';font-size:12.0pt;">module.<span style="color:#660e7a;font-weight:bold;">exports </span>= {<br /> <span style="color:#808080;font-style:italic;">// Uncommenting the defaults below <br /></span><span style="color:#808080;font-style:italic;"> // provides for an easier quick-start with Ganache.<br /></span><span style="color:#808080;font-style:italic;"> // You can also follow this format for other networks;<br /></span><span style="color:#808080;font-style:italic;"> // see <//truffleframework.com/docs/advanced/configuration><br /></span><span style="color:#808080;font-style:italic;"> // for more details on how to specify configuration options!<br /></span><span style="color:#808080;font-style:italic;"> /*<br /></span><span style="color:#808080;font-style:italic;"> networks: {<br /></span><span style="color:#808080;font-style:italic;"> development: {<br /></span><span style="color:#808080;font-style:italic;"> host: "127.0.0.1",<br /></span><span style="color:#808080;font-style:italic;"> port: 7545,<br /></span><span style="color:#808080;font-style:italic;"> network_id: "*"<br /></span><span style="color:#808080;font-style:italic;"> },<br /></span><span style="color:#808080;font-style:italic;"> test: {<br /></span><span style="color:#808080;font-style:italic;"> host: "127.0.0.1",<br /></span><span style="color:#808080;font-style:italic;"> port: 7545,<br /></span><span style="color:#808080;font-style:italic;"> network_id: "*"<br /></span><span style="color:#808080;font-style:italic;"> }<br /></span><span style="color:#808080;font-style:italic;"> }<br /></span><span style="color:#808080;font-style:italic;"> */<br /></span><span style="color:#808080;font-style:italic;"> </span><span style="color:#660e7a;font-weight:bold;">compilers</span>: {<br /> <span style="color:#660e7a;font-weight:bold;">solc</span>: {<br /> <span style="color:#660e7a;font-weight:bold;">version</span>: <span style="color:#008000;font-weight:bold;">"0.4.24"<br /></span><span style="color:#008000;font-weight:bold;"> </span>}<br /> }<br />};<br />5.再次编译,出?br />/C/users/administrator/webstormprojects/testtruffle/contracts/Migrations.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.4.24+commit.e67f0147.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version<br />pragma solidity >=0.4.25 <0.6.0;<br />^------------------------------^<br />6.打开Migrations.sol文件?br />把pragma solidity >=0.4.25 <0.6.0;<br />修改为:pragma solidity >=0.4.24 <0.6.0;<br />编译通过?br /></pre></div><img src ="//www.scdqe.tw/waterjava/aggbug/433949.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-06-25 09:05 <a href="//www.scdqe.tw/waterjava/archive/2019/06/25/433949.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> ipfs + 以太坊实例解?/title><link>//www.scdqe.tw/waterjava/archive/2019/06/25/433948.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Tue, 25 Jun 2019 00:21:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/06/25/433948.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/433948.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/06/25/433948.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/433948.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/433948.html</trackback:ping><description><![CDATA[本文章的项目基于春哥的博客教?br />【IPFS + 区块?系列?入门?- IPFS + Ethereum (下篇)-ipfs + Ethereum 大图片存?br /><br />我个人只是作为记录学习心得所借鉴<br />项目流程<br /><br />首先调用代码创建truffle项目<br /><br />    truffle unbox react<br /><br />其次,要引入ipfs的api,用作图片存储的相关功能,我们是将图片存储到ipfs当中,而将所获得图片的hash区块链之中,区块链大数据成本的问?br /><br />    npm install –save ipfs-api<br /><br />安装完毕调用complie编译合约代码,,以便使用web3调用合约存储区块?br /><br />    compile<br /><br />替换合约地址,这个需要将合约在以太坊部署并取得对应地址<br />然后运行ipfs节点<br /><br />    ipfs daemon<br /><br />启动项目<br /><br />    npm start<br /><br />就可以看到项目成?br />代码解读分析<br /><br />import React, {Component} from 'react'<br />import SimpleStorageContract from '../build/contracts/SimpleStorage.json'<br />import getWeb3 from './utils/getWeb3'<br /><br />import './css/oswald.css'<br />import './css/open-sans.css'<br />import './css/pure-min.css'<br />import './App.css'<br /><br />const ipfsAPI = require('ipfs-api');<br />const ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'});<br /><br />const contract = require('truffle-contract')<br />const simpleStorage = contract(SimpleStorageContract)<br />let account;<br /><br />/** Declaring this for later so we can chain functions on SimpleStorage.**/<br />let contractInstance;<br />//ipfs保存图片方法//<br />let saveImageOnIpfs = (reader) => {<br />  return new Promise(function(resolve, reject) {<br />    const buffer = Buffer.from(reader.result);<br />    ipfs.add(buffer).then((response) => {<br />      console.log(response)<br />      resolve(response[0].hash);<br />    }).catch((err) => {<br />      console.error(err)<br />      reject(err);<br />    })<br />  })<br />}<br /><br />//创建构造函数,添加状态机变量//<br /><br />class App extends Component {<br />  constructor(props) {<br />    super(props)<br /><br />    this.state = {<br />      blockChainHash: null,<br />      web3: null,<br />      address: null,<br />      imgHash: null,<br />      isWriteSuccess: false<br />    }<br />  }<br />//程序启动默认调用方法//<br />  componentWillMount() {<br />    //打印项目中网络节?/<br />    ipfs.swarm.peers(function(err, res) {<br />      if (err) {<br />        console.error(err);<br />      } else {<br />        /** var numPeers = res.Peers === null ? 0 : res.Peers.length;**/<br />        /** console.log("IPFS - connected to " + numPeers + " peers");**/<br />        console.log(res);<br />      }<br />    });<br />    //web3设置,同时调用初始化方法//<br />    getWeb3.then(results => {<br />      this.setState({web3: results.web3})<br /><br />      // Instantiate contract once web3 provided.<br />      this.instantiateContract()<br />    }).catch(() => {<br />      console.log('Error finding web3.')<br />    })<br />  }<br />    //初始化合约实例、web3获取合约账号以及合约实例//<br />  instantiateContract = () => {<br /><br />    simpleStorage.setProvider(this.state.web3.currentProvider);<br />    this.state.web3.eth.getAccounts((error, accounts) => {<br />      account = accounts[0];<br />      simpleStorage.at('0xf6a7e96860f05f21ecb4eb588fe8a8a83981af03').then((contract) => {<br />        console.log(contract.address);<br />        contractInstance = contract;<br />        this.setState({address: contractInstance.address});<br />        return;<br />      });<br />    })<br /><br />  }<br />  render() {<br />    return (<div className="App"><br />      {<br />        this.state.address<br />          ? <h1>合约地址:{this.state.address}</h1><br />          : <div/><br />      }<br />      <h2>上传图片到IPFS?lt;/h2><br />      /**这一部分用于上传文件到ipfs**/<br />      <div><br />        <label id="file">Choose file to upload</label><br />        <input type="file" ref="file" id="file" name="file" multiple="multiple"/><br />      </div><br />      <div><br />        <button onClick={() => {<br />            var file = this.refs.file.files[0];<br />            var reader = new FileReader();<br />            // reader.readAsDataURL(file);<br />            reader.readAsArrayBuffer(file)<br />            reader.onloadend = function(e) {<br />              console.log(reader);<br />              saveImageOnIpfs(reader).then((hash) => {<br />                console.log(hash);<br />                this.setState({imgHash: hash})<br />              });<br /><br />            }.bind(this);<br /><br />          }}>将图片上传到IPFS并返回图片HASH</button><br />      </div><br />       /**这一部分用于上传hash到区块链**/<br />      {<br />        this.state.imgHash<br />          ? <div><br />              <h2>imgHash:{this.state.imgHash}</h2><br />              <button onClick={() => {<br />                  contractInstance.set(this.state.imgHash, {from: account}).then(() => {<br />                    console.log('图片的hash已经写入到区块链?);<br />                    this.setState({isWriteSuccess: true});<br />                  })<br />                }}>将图片hash写到区块链:contractInstance.set(imgHash)</button><br />            </div><br />          : <div/><br />      }<br />      {<br />        this.state.isWriteSuccess<br />          ? <div><br />              <h1>图片的hash已经写入到区块链?lt;/h1><br />              <button onClick={() => {<br />                  contractInstance.get({from: account}).then((data) => {<br />                    console.log(data);<br />                    this.setState({blockChainHash: data});<br />                  })<br />                }}>从区块链读取图片hash:contractInstance.get()</button><br />            </div><br />          : <div/><br />      }<br />      {<br />        this.state.blockChainHash<br />          ? <div><br />              <h3>从区块链读取到的hash值:{this.state.blockChainHash}</h3><br />            </div><br />          : <div/><br />      }<br />      {<br />        this.state.blockChainHash<br />          ? <div><br />              <h2>浏览器访问:{"//localhost:8080/ipfs/" + this.state.imgHash}</h2><br />              <img alt="" style={{width:200}} src={"//localhost:8080/ipfs/" + this.state.imgHash}/><br />            </div><br />          : <img alt=""/><br />      }<br />    </div>);<br />  }<br />}<br /><br />export default App<br /><br /><br /><br />该项目算是truffle和ipfs结合以太坊一起使用的综合案例,用与梳理知识点<br />--------------------- <br />作者:czZ__czZ <br />来源:CSDN <br />原文:https://blog.csdn.net/czZ__czZ/article/details/79036567 <br />版权声明:本文为博主原创文章,转载请附上博文链接?img src ="//www.scdqe.tw/waterjava/aggbug/433948.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-06-25 08:21 <a href="//www.scdqe.tw/waterjava/archive/2019/06/25/433948.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JMS消息消费的顺序?/title><link>//www.scdqe.tw/paulwong/archive/2019/06/24/433942.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 24 Jun 2019 09:42:00 GMT</pubDate><guid>//www.scdqe.tw/paulwong/archive/2019/06/24/433942.html</guid><wfw:comment>//www.scdqe.tw/paulwong/comments/433942.html</wfw:comment><comments>//www.scdqe.tw/paulwong/archive/2019/06/24/433942.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/paulwong/comments/commentRss/433942.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/paulwong/services/trackbacks/433942.html</trackback:ping><description><![CDATA[现有的系统架构都是分布式的。有多个消息的发送者和多个消息的消费者。例如订单创建消息和订单支付消息,我们需要保证先消费订单创建消息,然后消费订单支付消息?br /><br />如何解决MQ消息消费顺序问题<br /><a target="_blank">https://segmentfault.com/a/1190000014512075</a><br /><br />jms-如何保证消息的顺?br /><a target="_blank">https://leokongwq.github.io/2017/01/23/jms-message-order.html</a><br /><br /><br /><br /><br /><br /><br /><br /><img src ="//www.scdqe.tw/paulwong/aggbug/433942.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/paulwong/" target="_blank">paulwong</a> 2019-06-24 17:42 <a href="//www.scdqe.tw/paulwong/archive/2019/06/24/433942.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nodejs-执行报错Error: Cannot find module 'express' - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/23/433936.html狼爱上狸狼爱上狸Sun, 23 Jun 2019 14:31:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/23/433936.html//www.scdqe.tw/waterjava/comments/433936.html//www.scdqe.tw/waterjava/archive/2019/06/23/433936.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/433936.html//www.scdqe.tw/waterjava/services/trackbacks/433936.html
  1. C:\Users\0>node E:\项目\2018年\11月份\nodejs\express_demo.js
  2. module.js:471
  3. throw err;
  4. ^
  5. Error: Cannot find module 'express'
  6. at Function.Module._resolveFilename (module.js:469:15)
  7. at Function.Module._load (module.js:417:25)
  8. at Module.require (module.js:497:17)
  9. at require (internal/module.js:20:19)
  10. at Object.<anonymous> (E:\项目\2018年\11月份\nodejs\express_demo.js:1:77)
  11. at Module._compile (module.js:570:32)
  12. at Object.Module._extensions..js (module.js:579:10)
  13. at Module.load (module.js:487:32)
  14. at tryModuleLoad (module.js:446:12)
  15. at Function.Module._load (module.js:438:3)
  16. C:\Users\0>express --version
  17. 4.16.0

实际上我是有安装express模块?/p>

奇了个怪了?/p>

然后试过1种方法是进入项目目录再执行安装express模块,无?/p>

最后,原来是node_modules没有配置环境变量

配置上吧?/p>

1、控制面板\所有控制面板项\系统\高级系统设置\环境变量

新建?#8216;NODE_PATH’:C:\Users\0\AppData\Roaming\npm\node_modules

 编辑增加环境变量‘PATH’

完美~~


//www.pianshen.com/article/837378161/




狼爱上狸 2019-06-23 22:31 发表评论
]]>
调用智能合约简单运算总返?的问?/title><link>//www.scdqe.tw/waterjava/archive/2019/06/23/433934.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Sun, 23 Jun 2019 10:12:00 GMT</pubDate><guid>//www.scdqe.tw/waterjava/archive/2019/06/23/433934.html</guid><wfw:comment>//www.scdqe.tw/waterjava/comments/433934.html</wfw:comment><comments>//www.scdqe.tw/waterjava/archive/2019/06/23/433934.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/waterjava/comments/commentRss/433934.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/waterjava/services/trackbacks/433934.html</trackback:ping><description><![CDATA[<pre style="background-color:#ffffff;color:#000000;font-family:'宋体';font-size:8.5pt;"><span style="color: #000080; font-weight: bold;">1.合约内容<br />pragma </span>solidity ^0.5.9;<br /><br /><span style="color:#000080;font-weight:bold;">contract </span>hello {<br /><br /> <span style="color:#000080;font-weight:bold;">function </span>mutiply(<span style="color:#000080;font-weight:bold;">uint </span>a) <span style="color:#000080;font-weight:bold;">public pure returns </span>(<span style="color:#000080;font-weight:bold;">uint </span>result) {<br /><br /> <span style="color:#000080;font-weight:bold;">return </span>a*<span style="color:#0000ff;">3</span>;<br /><br /> }<br />}<br />2.部署合约?br /><span style="color:#000080;font-weight:bold;">var </span>Web3 = require(<span style="color:#008000;font-weight:bold;">"web3"</span>);<br /><span style="color:#000080;font-weight:bold;">var </span>fs = require(<span style="color:#008000;font-weight:bold;">"fs"</span>);<br /><span style="color:#000080;font-weight:bold;">var </span>web3 = <span style="color:#000080;font-weight:bold;">new </span>Web3(<span style="color:#000080;font-weight:bold;">new </span>Web3.providers.HttpProvider(<span style="color:#008000;font-weight:bold;">'//localhost:8545'</span>));<br /><span style="color:#000080;font-weight:bold;">var </span>code = <span style="color:#008000;font-weight:bold;">'0x' </span>+ fs.readFileSync(<span style="color:#008000;font-weight:bold;">"2_sol_hello.bin"</span>).toString();<br /><span style="color:#000080;font-weight:bold;">var </span>abi = JSON.parse(fs.readFileSync(<span style="color:#008000;font-weight:bold;">"2_sol_hello.abi"</span>).toString());<br /><span style="color:#000080;font-weight:bold;">var </span>contract = web3.eth.contract(abi);<br />console.log(web3.eth.accounts);<br />console.log(<span style="color:#008000;font-weight:bold;">'account balance:' </span>+ web3.eth.getBalance(web3.eth.accounts[<span style="color:#0000ff;">0</span>]))<br /><br />web3.personal.unlockAccount(web3.eth.accounts[<span style="color:#0000ff;">0</span>],<span style="color:#008000;font-weight:bold;">"123"</span>)<br /><span style="color:#000080;font-weight:bold;">var </span>contract = contract.new({from: web3.eth.accounts[<span style="color:#0000ff;">0</span>], data: code, gas: <span style="color:#0000ff;">470000</span>},<br /> <span style="color:#000080;font-weight:bold;">function</span>(e, contract){<br /> <br /> <span style="color:#000080;font-weight:bold;">if</span>(!contract.address) {<br /> console.log(<span style="color:#008000;font-weight:bold;">"已经发起交易,交易地址? </span>+ contract.transactionHash + <span style="color:#008000;font-weight:bold;">"</span><span style="color:#000080;font-weight:bold;">\n</span><span style="color:#008000;font-weight:bold;">正在等待挖矿"</span>);<br /> } <span style="color:#000080;font-weight:bold;">else </span>{<br /> console.log(<span style="color:#008000;font-weight:bold;">"智能合约部署成功,地址? </span>+ contract.address);<br /> <br /> }<br /> <br /> } <br />)<br />3.调用合约<br /><span style="color:#000080;font-weight:bold;">var </span>Web3 = require(<span style="color:#008000;font-weight:bold;">"web3"</span>);<br /><span style="color:#000080;font-weight:bold;">var </span>fs = require(<span style="color:#008000;font-weight:bold;">"fs"</span>);<br /><span style="color:#000080;font-weight:bold;">var </span>web3 = <span style="color:#000080;font-weight:bold;">new </span>Web3(<span style="color:#000080;font-weight:bold;">new </span>Web3.providers.HttpProvider(<span style="color:#008000;font-weight:bold;">'//localhost:8545'</span>));<br /><span style="color:#000080;font-weight:bold;">var </span>abi = JSON.parse(fs.readFileSync(<span style="color:#008000;font-weight:bold;">"2_sol_hello.abi"</span>).toString());<br /><span style="color:#000080;font-weight:bold;">var </span>contract = web3.eth.contract(abi);<br /><span style="color:#000080;font-weight:bold;">var </span>instance = contract.at(<span style="color:#008000;font-weight:bold;">'0xb06846c54c6ae67102ed67ce57a357a643d1f1b8'</span>)<br />web3.personal.unlockAccount(web3.eth.accounts[<span style="color:#0000ff;">0</span>],<span style="color:#008000;font-weight:bold;">"123"</span>)<br />console.log(instance.mutiply(<span style="color:#0000ff;">12</span>).toString())<br />4.显示结果为:<br />0<br />原因:solc版本0.5.9太高,可能调用的方法不对?br />解决方法:npm install -g solc@0.4.22<br />降低版本,然后把合约第一行改为:<br /><span style="color: #000080; font-weight: bold;">pragma </span>solidity ^0.4.22;<br />问题解决?br /><br /></pre><img src ="//www.scdqe.tw/waterjava/aggbug/433934.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/waterjava/" target="_blank">狼爱上狸</a> 2019-06-23 18:12 <a href="//www.scdqe.tw/waterjava/archive/2019/06/23/433934.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>多维度对?款主流分布式MQ消息队列,妈妈再也不担心我的技术选型?/title><link>//www.scdqe.tw/jb2011/archive/2019/06/21/433917.html</link><dc:creator>Jack Jiang</dc:creator><author>Jack Jiang</author><pubDate>Fri, 21 Jun 2019 07:01:00 GMT</pubDate><guid>//www.scdqe.tw/jb2011/archive/2019/06/21/433917.html</guid><wfw:comment>//www.scdqe.tw/jb2011/comments/433917.html</wfw:comment><comments>//www.scdqe.tw/jb2011/archive/2019/06/21/433917.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.scdqe.tw/jb2011/comments/commentRss/433917.html</wfw:commentRss><trackback:ping>//www.scdqe.tw/jb2011/services/trackbacks/433917.html</trackback:ping><description><![CDATA[     摘要: 1、引言对于即时通讯网来说,所有的技术文章和资料都在围绕即时通讯这个技术方向进行整理和分享,这一次也不例外。对于即时通讯系统(包括IM、消息推送系统等)来说,MQ消息中件间是非常常见的基础软件,但市面上种类众多、各有所长的MQ消息中件间产品,该怎么去选择?这是个问题!对于很多经验不足的开发者来说,一个公司内部用的IM聊天系统,总用户量也不过百十来人,动辄就是Kafka、MongoDB,美其名曰为?..  <a href='//www.scdqe.tw/jb2011/archive/2019/06/21/433917.html'>阅读全文</a><img src ="//www.scdqe.tw/jb2011/aggbug/433917.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.scdqe.tw/jb2011/" target="_blank">Jack Jiang</a> 2019-06-21 15:01 <a href="//www.scdqe.tw/jb2011/archive/2019/06/21/433917.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Multiple MongoDB connectors with Spring Boot - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/06/20/433910.htmlpaulwongpaulwongThu, 20 Jun 2019 07:12:00 GMT//www.scdqe.tw/paulwong/archive/2019/06/20/433910.html//www.scdqe.tw/paulwong/comments/433910.html//www.scdqe.tw/paulwong/archive/2019/06/20/433910.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/433910.html//www.scdqe.tw/paulwong/services/trackbacks/433910.html//blog.marcosbarbero.com/multiple-mongodb-connectors-in-spring-boot/



paulwong 2019-06-20 15:12 发表评论
]]>
以太坊(二)MAC搭建以太坊私有链多节点集群(同一台电脑) - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/20/433909.html狼爱上狸狼爱上狸Thu, 20 Jun 2019 06:47:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/20/433909.html//www.scdqe.tw/waterjava/comments/433909.html//www.scdqe.tw/waterjava/archive/2019/06/20/433909.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/433909.html//www.scdqe.tw/waterjava/services/trackbacks/433909.html

狼爱上狸 2019-06-20 14:47 发表评论
]]>
web3.php Error: The method personal_newAccount does not exist/is not available - 2017ϹƱ̳ͼ//www.scdqe.tw/waterjava/archive/2019/06/19/433900.html狼爱上狸狼爱上狸Wed, 19 Jun 2019 02:42:00 GMT//www.scdqe.tw/waterjava/archive/2019/06/19/433900.html//www.scdqe.tw/waterjava/comments/433900.html//www.scdqe.tw/waterjava/archive/2019/06/19/433900.html#Feedback0//www.scdqe.tw/waterjava/comments/commentRss/433900.html//www.scdqe.tw/waterjava/services/trackbacks/433900.html很多人遇到这个问?

web3.php Error: The method personal_newAccount does not exist/is not available?/p>

其实很简单,我们只需要在geth启动时的rpc参数中设置rpcapi时包?"personal" 即可?/p>

geth --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi eth,web3,admin,personal,net


来自://www.bcfans.com/toutiao/redian/101819.html


我的是:
geth --identity "Water" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir gethdata --port "30303" --nodiscover --rpcapi "db,eth,net,personal,web3" --networkid 1999 init genesis.json


狼爱上狸 2019-06-19 10:42 发表评论
]]>
NFS Server 架設 - 2017ϹƱ̳ͼ//www.scdqe.tw/paulwong/archive/2019/06/18/433884.htmlpaulwongpaulwongTue, 18 Jun 2019 01:08:00 GMT//www.scdqe.tw/paulwong/archive/2019/06/18/433884.html//www.scdqe.tw/paulwong/comments/433884.html//www.scdqe.tw/paulwong/archive/2019/06/18/433884.html#Feedback0//www.scdqe.tw/paulwong/comments/commentRss/433884.html//www.scdqe.tw/paulwong/services/trackbacks/433884.html
  • 安裝 nfs-utils 套件?pre>
    [root@kvm5 ~]# yum install -y nfs-utils
  • 建立 NFS 分享目錄?pre>
    [root@kvm5 ~]# mkdir /public /protected
  • 修改 NFS 分享目錄?SELinux 檔案 context?pre>
    [root@kvm5 ~]# semanage fcontext -a -t public_content_t "/public(/.*)?"
    [root@kvm5 ~]# semanage fcontext -a -t public_content_t "/protected(/.*)?"
    [root@kvm5 ~]# restorecon -Rv /public /protected
  • 考試時不用自行產?kerberos keytab,只要依照指定的位置下載,存放在目錄 /etc/ 下,且檔名必須為 krb5.keytab?pre>
    [root@kvm5 ~]# wget //deyu.wang/kvm5.keytab -O /etc/krb5.keytab 
  • kerberos keytab 的驗證跟時間有關,server ?client 都必須校時?pre>
    [root@kvm5 ~]# date
    Sun Jan  7 14:50:04 CST 2018
    [root@kvm5 ~]# chronyc -a makestep
    200 OK
    200 OK
    [root@kvm5 ~]# date
    Mon Nov 20 15:53:22 CST 2017
  • ?/protected 下建立次目錄 restricted,並將其擁有者設定為 deyu3,讓 deyu3 可以寫入資料?pre>
    [root@kvm5 ~]# mkdir -p  /protected/restricted 
    [root@kvm5 ~]# chown deyu3 /protected/restricted 
  • 編輯設定?/etc/exports,分?/protected ?/public 兩個目錄給網域 192.168.122.0/24?pre>
    [root@kvm5 ~]# echo '/protected 192.168.122.0/24(rw,sync,sec=krb5p)' > /etc/exports
    [root@kvm5 ~]# echo '/public 192.168.122.0/24(ro,sync)' >> /etc/exports
    [root@kvm5 ~]# vim /etc/exports
    [root@kvm5 ~]# cat /etc/exports
    /protected 192.168.122.0/24(rw,sync,sec=krb5p)
    /public 192.168.122.0/24(ro,sync)

  • NFS 掛載參數說明如下,詳細說明請參?man 5 nfs 手冊?ol>
  • rw:read-write,可讀寫的權限?/li>
  • ro:read-only,唯讀的權限;
  • sec=mode:安全認證模式;
    1. sec=sys 預設,使用本?UNIX UIDs ?GIDs 進行身份認證?/li>
    2. sec=krb5 使用 Kerberos V5 取代本地 UNIX UIDs ?GIDs 進行身份認證?/li>
    3. sec=krb5i 使用 Kerberos V5 進行身份認證,資料完整性檢查,以防止數據被篡改?/li>
    4. sec=krb5p 使用 Kerberos V5 進行身份認證,資料完整性檢查及 NFS 傳輸加密,以防止數據被篡改,這是最安全的方式?/li>
  • sync:資料同步寫入到記憶體與硬碟當中?/li>
    [root@kvm5 ~]# man 5 nfs 
  • 設定使用 4.2 版本,以匯出分享 SELinux context。無適合的版?client 端掛載時會出?mount.nfs: Protocol not supported 的訊息?pre>
    [root@kvm5 ~]# vim /etc/sysconfig/nfs  sed -i 's/^\(RPCNFSDARGS=\).*$/\1\"-V 4.2\"/' /etc/sysconfig/nfs 
    [root@kvm5 ~]# grep ^RPCNFSDARGS /etc/sysconfig/nfs  RPCNFSDARGS="-V 4.2" 
  • 設定開機啟動 nfs 服務,NFS server 端的服務?nfs-server ?nfs-secure-server,本版本只要啟動 nfs-server 就同時啟?nfs-secure-server,而且使用 tab 鍵也不會出現 nfs-secure-server 服務,但有些版本則是兩者分開,必須確認是不是兩種服務都啟動?pre>
    [root@kvm5 ~]# systemctl enable nfs-server.service nfs-secure-server.service 
  • 啟動 nfs 服務
    [root@kvm5 ~]# systemctl start nfs-server.service nfs-secure-server.service 
  • 查看目前啟動?nfs 版本,因 server 指定使用 4.2,若出現 -4.2 表示 nfs server 沒有成功啟動?pre>
    [root@kvm5 ~]# cat /proc/fs/nfsd/versions -2 +3 +4 +4.1 +4.2 
  • 要確?nfs-secure-server nfs-server 服務都正常運作?pre>
    [root@kvm5 ~]# systemctl status nfs-secure-server.service nfs-server.service 
    nfs-secure-server.service - Secure NFS Server
       Loaded
    : loaded (/usr/lib/systemd/system/nfs-secure-server.service; enabled)
       Active
    : active (running) since Mon 2015-09-21 20:04:10 CST; 8s ago
      Process
    : 3075 ExecStart=/usr/sbin/rpc.svcgssd $RPCSVCGSSDARGS (code=exited, status=0/SUCCESS)
     Main PID
    : 3077 (rpc.svcgssd)
       CGroup
    : /system.slice/nfs-secure-server.service
               └─
    3077 /usr/sbin/rpc.svcgssd

    Sep 
    21 20:04:10 kvm5.deyu.wang systemd[1]: Starting Secure NFS Server
    Sep 
    21 20:04:10 kvm5.deyu.wang systemd[1]: Started Secure NFS Server.

    nfs
    -server.service - NFS Server
       Loaded
    : loaded (/usr/lib/systemd/system/nfs-server.service; enabled)
       Active
    : active (exited) since Mon 2015-09-21 20:04:10 CST; 8s ago
      Process
    : 3078 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
      Process
    : 3076 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
      Process
    : 3087 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT (code=exited, status=0/SUCCESS)
      Process
    : 3084 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
      Process
    : 3083 ExecStartPre=/usr/libexec/nfs-utils/scripts/nfs-server.preconfig (code=exited, status=0/SUCCESS)
     Main PID
    : 3087 (code=exited, status=0/SUCCESS)
       CGroup
    : /system.slice/nfs-server.service

    Sep 
    21 20:04:10 kvm5.deyu.wang systemd[1]: Starting NFS Server
    Sep 
    21 20:04:10 kvm5.deyu.wang systemd[1]: Started NFS Server.
  • 建議不論是否 TAB 有沒有出現提示,都同時啟動這兩個服務。CentOS 安裝版本 nfs-utils-1.3.0-8.el7.x86_64 啟動 nfs-secure-server 出現錯誤訊息,請執行 yum downgrade nfs-utils 換成 nfs-utils-1.3.0-0.el7.x86_64 套件?pre>
    [root@kvm5 ~]# rpm -qa | grep nfs-utils
    nfs-utils-1.3.0-8.el7.x86_64
    [root
    @kvm5 ~]# yum downgrade nfs-utils -y
    [root@kvm5 ~]# rpm -qa | grep nfs-utils
    nfs-utils-1.3.0-0.el7.x86_64
  • 再重新啟?nfs 服務,並查看是否正常運作?pre>
    [root@kvm5 ~]# systemctl restart nfs-server.service nfs-secure-server.service 
  • 輸出所有設定的 nfs 分享目錄?pre>
    [root@kvm5 ~]# exportfs -arv
    exporting 192.168.122.0/24:/public
    exporting 
    192.168.122.0/24:/protected


  • 2017ϹƱ̳ͼ 2019-06-18 09:08 发表评论
    ]]>