mule做了一周多了,入门很难,光跑那几个demo就很费事情,它提供的很多东西都和文档上的不一致,这点真的想骂人,不成熟的东西就不要拿出来啊,拿出来又用不起,老板又不听这种解释。。。。我真的苦啊!!!
不过总算过头了,我成功的调通了mule的xmpp路由功能,虽然里面有bug,但我自己写了一个类的代替它,勉强可以用了。
下面我把如何配置xml文件以及如果启动告诉大家,希望对大家有些帮助,不用再花费太多时间去研究!
下面是一个完整可运行的,通过测试的xml
,
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
xmlns:tcp="http://www.mulesource.org/schema/mule/tcp/2.2"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
http://www.mulesource.org/schema/mule/tcp/2.2 http://www.mulesource.org/schema/mule/tcp/2.2/mule-tcp.xsd
http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">
<custom-transformer name="StdinToNameString" class="org.mule.example.hello.StdinToNameString"/>
<custom-transformer name="NameStringToChatString" class="org.mule.example.hello.NameStringToChatString"/>
<custom-transformer name="ChatStringToString" class="org.mule.example.hello.ChatStringToString"/>
<custom-transformer name="ExceptionToString" class="org.mule.example.hello.ExceptionToString"/>
<custom-transformer name="StringToString" class="transformer.StringToString"></custom-transformer>
<custom-transformer name="XmppPacketToObject" class="org.mule.transport.xmpp.transformers.XmppPacketToObject"/>
<custom-transformer name="ObjectToXmppPacket" class="org.mule.transport.xmpp.transformers.ObjectToXmppPacket"/>
<custom-transformer name="XmppPacketToString" class="xmpp.XmppPacketToString"/>
<custom-transformer name="ByteArrayToObject" class="org.mule.transformer.simple.ByteArrayToObject"/>
<custom-transformer name="ObjectToTempXmppPacket" class="xmpp.ObjectToTempXmppPacket"/>
<!--
An interceptor is a piece of code that can be configured to execute
before and/or after an event is received for a component.
You can define a stack of interceptors that will be executed in sequence.
You can then configure the stack on your components.
-->
<!--
The Mule model initialises and manages your UMO components
-->
<tcp:connector name="TcpConnector"
keepAlive="true" receiveBufferSize="2048" sendBufferSize="2048"
receiveBacklog="500" serverSoTimeout="3000"
keepSendSocketOpen="true" validateConnections="true">
<tcp:direct-protocol payloadOnly="true"/>
</tcp:connector>
<tcp:endpoint connector-ref="TcpConnector" name="Endpoint" host="192.168.1.20" port="5200" synchronous="true"/>
<model name="helloSample">
<!--
A Mule service defines all the necessary information about how your components will
interact with the framework, other components in the system and external sources.
Please refer to the Configuration Guide for a full description of all the parameters.
-->
<service name="GreeterUMO">
<inbound>
<tcp:inbound-endpoint name="inboundEndpoint" connector-ref="TcpConnector"
port="5200" host="192.168.1.20" transformer-refs="ByteArrayToObject ObjectToTempXmppPacket"/>
<!-- <inbound-endpoint ref="inboundEndpoint"/>-->
</inbound>
<!-- <component class="xmpp.XmppOtherComponet"/>-->
<outbound>
<filtering-router>
<vm:outbound-endpoint path="iq"/>
<payload-type-filter expectedType="beans.Person"/>
</filtering-router>
<filtering-router>
<vm:outbound-endpoint path="iq"/>
<payload-type-filter expectedType="qflag.xmpp.packet.IQ"/>
</filtering-router>
<filtering-router>
<vm:outbound-endpoint path="message"/>
<payload-type-filter expectedType="qflag.xmpp.packet.Message"/>
</filtering-router>
<!-- <filtering-router>-->
<!-- <vm:outbound-endpoint path="message"/>-->
<!-- <payload-type-filter expectedType="qflag.xmpp.packet.IQ"/>-->
<!-- </filtering-router>-->
<filtering-router>
<vm:outbound-endpoint path="userErrorHandler"/>
<payload-type-filter expectedType="java.lang.Exception"/>
</filtering-router>
</outbound>
<!-- Route unexpected errors to separate error handler -->
<default-service-exception-strategy>
<vm:outbound-endpoint path="systemErrorHandler"/>
</default-service-exception-strategy>
</service>
<service name="IQUMO">
<inbound>
<vm:inbound-endpoint path="iq" responseTransformer-refs="StringToString" />
</inbound>
<component class="xmpp.service.IQService" />
<!-- Route unexpected errors to separate error handler -->
<default-service-exception-strategy>
<vm:outbound-endpoint path="systemErrorHandler"/>
</default-service-exception-strategy>
</service>
<service name="MessageUMO">
<inbound>
<vm:inbound-endpoint path="message" />
</inbound>
<component class="xmpp.service.MessageService"/>
<!-- Route unexpected errors to separate error handler -->
<default-service-exception-strategy>
<vm:outbound-endpoint path="systemErrorHandler"/>
</default-service-exception-strategy>
</service>
<!-- This error handler returns user error messages to caller. Errors could also be routed elsewhere,
e.g. into an error file, send via email to a list, stored in a database, etc. -->
<service name="UserErrorHandler">
<inbound>
<vm:inbound-endpoint path="userErrorHandler" transformer-refs="ExceptionToString"/>
</inbound>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="OUT"/>
</pass-through-router>
</outbound>
</service>
<!-- Handle any unexpected errors. Errors could also be routed elsewhere,
e.g. into an error file, send via email to a list, stored in a database, etc. -->
<service name="SystemErrorHandler">
<inbound>
<vm:inbound-endpoint path="systemErrorHandler"/>
</inbound>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="ERR"/>
</pass-through-router>
</outbound>
</service>
</model>
<!----><!----><!----> <!----><!----><!----><!---->