camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Netty for TCP communication
Date Wed, 28 Dec 2011 14:59:02 GMT
On Wed, Dec 28, 2011 at 2:50 PM, xiangqiuzhao <xiangqiuzhao@gmail.com> wrote:
> i had implements my Decoder named MessageDecoder. and use by
> from("host:port?decoder=com.test.MessageDecoder"), but where i need to put
> the class?

Hi

You need to use the # syntax to refer to a bean id, from the Registry,
which is your custom decoder.

See for example the hl7 wiki page with the hl7 codec
http://camel.apache.org/hl7



>
> second, why need use decoders and encoders? if i need implements some
> decoder, why not to implements
> a big decoder?
>
> public class MessageDecoder extends FrameDecoder {
>
>    @Override
>    protected Object decode(
>            ChannelHandlerContext ctx, Channel channel, ChannelBuffer
> buffer) throws Exception {
>        if (buffer.readableBytes() < 4) {
>            return null;//(1)
>        }
>        int dataLength = buffer.getInt(buffer.readerIndex());
>        if (buffer.readableBytes() < dataLength + 4) {
>            return null;//(2)
>        }
>
>        buffer.skipBytes(4);//(3)
>        byte[] decoded = new byte[dataLength];
>        buffer.readBytes(decoded);
>        String msg = new String(decoded);//(4)
>        return msg;
>    }
> }
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Netty-for-TCP-communication-tp3409969p5105286.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message