|
| 1 | +:test-examples: ../../test/java/com/rabbitmq/stream/docs |
| 2 | + |
| 3 | +=== Advanced Topics |
| 4 | + |
| 5 | +==== Using Native `epoll` |
| 6 | + |
| 7 | +The stream Java client uses the https://netty.io/[Netty] network framework and its Java NIO transport implementation by default. |
| 8 | +This should be a reasonable default for most applications. |
| 9 | + |
| 10 | +Netty also allows using https://netty.io/wiki/native-transports.html[JNI transports]. |
| 11 | +They are less portable than Java NIO, but they can be more performant for some workloads (even though the RabbitMQ team has not seen any significant improvement in their own tests). |
| 12 | + |
| 13 | +The https://en.wikipedia.org/wiki/Epoll[Linux `epoll` transport] is a popular choice, so we'll see how to configure with the stream Java client. |
| 14 | +Other JNI transports can be configured in the same way. |
| 15 | + |
| 16 | +The native transport dependency must be added to the dependency manager. |
| 17 | +We must pull the native binaries compiled for our OS and architecture, in our example Linux x86-64, so we are using the `linux-x86_64` classifier. |
| 18 | +Here is the declaration for Maven: |
| 19 | + |
| 20 | +.Declaring the Linux x86-64 native `epoll` transport dependency with Maven |
| 21 | +[source,xml,subs="attributes,specialcharacters"] |
| 22 | +---- |
| 23 | +<dependencies> |
| 24 | +
|
| 25 | + <dependency> |
| 26 | + <groupId>io.netty</groupId> |
| 27 | + <artifactId>netty-transport-native-epoll</artifactId> |
| 28 | + <version>{netty-version}</version> |
| 29 | + <classifier>linux-x86_64</classifier> |
| 30 | + </dependency> |
| 31 | +
|
| 32 | +</dependencies> |
| 33 | +---- |
| 34 | + |
| 35 | +And for Gradle: |
| 36 | + |
| 37 | +.Declaring the Linux x86-64 native `epoll` transport dependency with Gradle |
| 38 | +[source,groovy,subs="attributes,specialcharacters"] |
| 39 | +---- |
| 40 | +dependencies { |
| 41 | + compile "io.netty:netty-transport-native-epoll:{netty-version}:linux-x86_64" |
| 42 | +} |
| 43 | +---- |
| 44 | + |
| 45 | +The native `epoll` transport is set up when the environment is configured: |
| 46 | + |
| 47 | +.Configuring the native `epoll` transport in the environment |
| 48 | +[source,java,indent=0] |
| 49 | +-------- |
| 50 | +include::{test-examples}/EnvironmentUsage.java[tag=native-epoll] |
| 51 | +-------- |
| 52 | +<1> Create the `epoll` event loop group (don't forget to close it!) |
| 53 | +<2> Use the Netty configuration helper |
| 54 | +<3> Set the event loop group |
| 55 | +<4> Set the channel class to use |
| 56 | + |
| 57 | +Note the event loop group must be closed explicitly: the environment will not close it itself as it is provided externally. |
0 commit comments