问题描述:

I am new to Netty but unfortunately there seems to be no detailed documentation/tutorial for a beginner.

I have multiple threads, each creating separate clients to connect to separate channels, using NettyChannelBuilder. The idea is that each channel will send & receive different kind of messages to/from different hosts. E.g. it looks like this:

class MyServiceClass{

void executeTasks() {

...

//here multiple tasks are executed in a for loop

executorService.execute(new Task(new Client());

...

}

}

class Client {

..

void connect() {

channel = NettyChannelBuilder.forAddress(host, port).build();

}

}

In this case, each task has its own client and clients are building their own channels to receive messages.

Should i create a single EventLoopGroup at executeTasks and give it to the Clients to be used while building their channel.

If this is the case, what is the advantage of using EventLoopGroup? What is it exactly doing at the background?

网友答案:

I'm not sure what you're asking. EventLoopGroups are just a grouping of threads used for netty. Using netty your clients will be on an EventLoopGroup and will be assigned to threads in a round robin matter so some may be on the same thread.

Personally I find the docs to be great but it's definitely not a framework designed for beginners.

相关阅读:
Top