Minamule has moved: official MinaMule page at MuleSource

An asynchronous transport for permanent socket connections

MinaMule allow to manage socket connections in an asynchronous way using the ESB Mule
Simply speaking, it permits to not use a thread to keep the connection open while a request is processed or data is sent.

Features:

  • Efficient for protocols that uses long lasting connections, permanent connections, sending of large quantities of data, streaming
  • Optimized threads utilization (manage all the connections with few threads)
  • Since it uses the Mina library it will ease the integration of protocols made with Mina with Mule
  • Mina is rapidly evolving and performance improvements in Mina will be reflected in this transport

The code is arranged to ease the development of Mule transport with those features.

Beware that this code is to be intended as a proof-of-concept.

"MinaMule" is the object of the final thesis for the bachelor degree of Marco D'Alia.

News

I've added streaming capabilities to the transport: if a component send an InputStream it will be consumed gradually as it is sent You can try it with the MinaStreamingServer example.

To check that it actually streams the data you can use wget:

wget http://localhost:8888 --limit-rate 10000

It is not orthodox but it seems to work

Future possibilities

This library can be useful to integrate with Mule some emerging servers like AsynchWeb and the recent Adobe Flash media server Red5: http://osflash.org/red5

It is also possible to implement transports for protocols that need a connection for client. In this way will not be required a thread on the server for every client.

Every protocol can benefit from this approach because Mina will handle all the network activity like connecting and transferring bytes in a more efficient way than a-thread-for-connection.

How it works

There are two sample transports implemented: MinaCodec and MinaHttp.
MinaCodec allow simple tcp communications.

When it is used as an inbound router:

<inbound-router>
   <endpoint name="minaEndpoint" address="mina://localhost:8888" synchronous="false">

     <properties>
        <property name="protocolFactory" value="org.mule.providers.mina.codec.codecs.SimpleTextLineCodecFactory" />
     </properties>
   </endpoint>

</inbound-router>

It will accept connections in the specified port and will decode the byte received with the specified codecs (in the portocolFactory).

Every client connected will be associated to a Mina session, and every session to an Id. This Id will be put in the MuleMessage property "MINA_SESSION_ID". Since the Mule messages are dispatched asynchronously, it is necessary to specify the outbound router or a reply-to:

<outbound-router>
   <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
      <endpoint address="mina://localhost:8888" synchronous="true" />

   </router>
</outbound-router>

The outbound endpoint address must match exactly the inbound one.

In this way, when a reply is send back to the endpoint, the dispatcher will use the MINA_SESSION_ID property to find the client who made the request and to reply to him.

When it is used for making connection to a remote host (outbound endpoint):

when a request arrive at the endpoint the dispatcher will instruct Mina to make a connection and send the message.

When a reply will be received by Mina, it will be routed back to the reply-to endpoint.

<outbound-router>
  <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
    <endpoint name="tcpOut2" address="mina://localhost:8888" synchronous="false">

      <properties>
        <property name="protocolFactory" value="org.mule.providers.mina.codec.codecs.SimpleTextLineCodecFactory" />
      </properties>
    </endpoint>

    <reply-to address="minahttp://localhost:80/foo" />
  </router>
</outbound-router>

In this example the replies from requests made by Mule to the localhost:8888 server will be routed to minahttp://localhost:80/foo endpoint.

Try it

Browse the repository to see the code.

There are 3 subprojects:

  • Transport: there is the code for the base classes needed to implement a transport with Mina plus two protocol: MinaCodec (Tcp) and MinaHttp (Http)
  • Examples: there are some Mule configuration examples using those transports:
    • MinaEchoServer.java: a simple tcp echo server on the port 8888
    • MinaHttpEchoServer.java: a simple http echo server: http://localhost/foo/?msg=hello
    • MinaClient.java: a server that accept tcp and http requests and foward them to MinaEchoServer (You need to start MinaEchoServer first)
  • Benchmarks: There are two simple programs to do some stress-testing on the servers:
    • Client: make a large quantity of request to an http server
    • StatsClient: monitor the response time of an http server

Files

All the code is avaibile in the subversion repository.
To run it you need:

  • Mule>=1.3
  • Mina 1.0.1
  • Java 5

I've made a fat-jar with all the dependencies: http://minamule.madarco.net/MinaMuleDependencies.jar
And one with all the .java and .class: http://minamule.madarco.net/MinaMule.jar

The subversion repository can be found here: http://minamule.madarco.net/svn

Copyright Notice

This program is distrubuted as-is bla bla bla ecc.. and you can do whatever you want with it (Public Domain)