视频网站切片怎么做,如何做网站结构及栏目策划,创建网站用突唯阿做响应式网站,企业注册号怎么查询这是Spring Integration Session 1的后续活动 第一部分是使用Spring Integration的简单Hello World应用程序。 我想通过考虑其他一些方案来进一步介绍它。 因此#xff0c;对Hello World应用程序的第一个更改是添加网关组件。 要快速重新访问较早的测试程序#xff0c;请执行… 这是Spring Integration Session 1的后续活动 第一部分是使用Spring Integration的简单Hello World应用程序。 我想通过考虑其他一些方案来进一步介绍它。 因此对Hello World应用程序的第一个更改是添加网关组件。 要快速重新访问较早的测试程序请执行以下操作 package org.bk.si.helloworld.hw1;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;RunWith(SpringJUnit4ClassRunner.class)
ContextConfiguration(helloworld.xml)
public class HelloWorldTest {AutowiredQualifier(messageChannel)MessageChannel messageChannel;Testpublic void testHelloWorld() {MessageString helloWorld new GenericMessageString(Hello World);messageChannel.send(helloWorld);}
} 在上面突出显示的行中测试依赖于特定于Spring Integration的组件-消息通道并且在测试中构造了显式的Spring Integration Message并将其发送到消息通道。 与Spring Integration这里的消息传递系统的耦合有点过多。 网关组件为消息传递系统提供了外观从而将用户应用程序在本例中为单元测试与消息传递系统的详细信息消息传递通道消息和消息的显式发送隔离开来。 首先通过一个示例来说明在使用网关组件的情况下测试的外观 package org.bk.si.helloworld.hw2;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;RunWith(SpringJUnit4ClassRunner.class)
ContextConfiguration(helloworld.xml)
public class HelloWorldTest {Autowired Greeter greeter;Testpublic void testHelloWorld(){this.greeter.sendGreeting(Hello World);}
} 上面的Greeter接口是网关组件。 既然已经引入了该组件那么在此测试中就不再依赖于Spring Integration了-在代码中根本没有提到MessageMessage Channel。 网关组件也是这样定义的非常简单的Java接口 package org.bk.si.helloworld.hw2;public interface Greeter {public void sendGreeting(String message);
} 所以现在的问题是谁来负责创建消息传递并将消息发送到消息通道–是通过Spring Integration配置进行的 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:inthttp://www.springframework.org/schema/integrationxmlns:int-streamhttp://www.springframework.org/schema/integration/streamxsi:schemaLocationhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdint:channel idmessagesChannel/int:channelint:gateway service-interfaceorg.bk.si.helloworld.hw2.Greeter default-request-channelmessagesChannel/int:gatewayint-stream:stdout-channel-adapter channelmessagesChannel append-newlinetrue//beans 上面突出显示的行从Greeter界面创建了Gateway组件在后台创建了一个代理该代理处理了之前明确进行的所有操作-创建消息传递并将消息发送到消息通道。 现在为“ Hello World”示例增加更多的复杂性 考虑以下测试 package org.bk.si.helloworld.hw3;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;RunWith(SpringJUnit4ClassRunner.class)
ContextConfiguration(helloworld.xml)
public class HelloWorldTest {Autowired Greeter greeter;Testpublic void testHelloWorld(){System.out.println(Started..);long start System.nanoTime();for (int i0;i10;i){this.greeter.sendMessage(String.format(Hello World %d,i));}System.out.println(Completed..);System.out.println(String.format(Took %f ms, (System.nanoTime()-start)/10e6));}
} 这与先前的单元测试相同除了在这种情况下“ Hello World”消息被发送了10次。 支持的Spring Integration配置文件如下 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:inthttp://www.springframework.org/schema/integrationxmlns:int-streamhttp://www.springframework.org/schema/integration/streamxsi:schemaLocationhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdint:publish-subscribe-channel idmessagesChannel/int:gateway service-interfaceorg.bk.si.helloworld.hw3.Greeter default-request-channelmessagesChannel/int:gatewayint-stream:stderr-channel-adapter channelmessagesChannel append-newlinetrue/int-stream:stdout-channel-adapter channelmessagesChannel append-newlinetrue//beans 如果我现在运行此测试则输出如下 红色的行打印到syserr黑色的行打印到sysout。 因此问题在于为什么其中一些将进入sysout而另一些将进入syserr为什么不同时使用呢 答案是因为通道的类型-上面的“ messagesChannel”是Spring Integration术语中的“直接通道”并且具有“点对点”语义。 点对点语义基本上意味着当一条消息进入Messaging Channel时只有1个接收者接收到该消息–因此在这种情况下标准输出适配器或标准err适配器最终都会打印进入该消息的消息。消息通道。 因此要打印到两个适配器解决方法是简单地更改通道的语义–代替点对点通道将其设置为发布-订阅通道该通道是向多个接收者广播消息的通道。 使用Spring Integration进行更改非常简单 file:/C:/learn/scratch/target/test-classes/org/bk/htmlencode/content.txt
?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:inthttp://www.springframework.org/schema/integrationxmlns:int-streamhttp://www.springframework.org/schema/integration/streamxsi:schemaLocationhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdint:publish-subscribe-channel idmessagesChannel/int:gateway service-interfaceorg.bk.si.helloworld.hw3.Greeter default-request-channelmessagesChannel/int:gatewayint-stream:stderr-channel-adapter channelmessagesChannel append-newlinetrue/int-stream:stdout-channel-adapter channelmessagesChannel append-newlinetrue//beans 现在的输出将是同时打印到sysout和syserr的消息 这样就完成了对网关组件直接通道和发布订阅通道的介绍。 参考资料 Spring Integration –第2节–来自all和各式博客的JCG合作伙伴 Biju Kunjummen的更多Hello Worlds 。 翻译自: https://www.javacodegeeks.com/2012/07/spring-integration-session-2-more-hello.html