How do I tell Aeron which port range to use?¶
This feature was introduced with Aeron 1.42.0. The port manager will only supply ports to items which have a
:0 in the channel configuration. Channels with specific ports selected are not impacted.
You want the Media Driver to select ports from a given range, to simplify firewall or other configuration.
Make use of the port manager configuration now found in the Media Driver Context. There is a built-in implementation of the
io.aeron.driver.media.PortManager interface called
io.aeron.driver.media.WildcardPortManager which allows port range selection.
First, define the desired port range. For this example, the desired port range will run from port 1000-2000. Port ranges are defined within an
int, with the first entry being the starting low port and the second entry being the ending high port:
public static int SAMPLE_PORT_RANGE = new int; SAMPLE_PORT_RANGE=1000; SAMPLE_PORT_RANGE=2000;
Then within the Media Driver Context:
final MediaDriver.Context context = new MediaDriver.Context() ... .senderPortManager(new WildcardPortManager(SAMPLE_PORT_RANGE, true)) .receiverPortManager(new WildcardPortManager(SAMPLE_PORT_RANGE, false));
The second parameter to the
WildcardPortManager informs the
WildcardPortManager if it is being used as a provider of sender ports, or not.