You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Shri Ram <sh...@gmail.com> on 2020/09/22 05:35:15 UTC

How to bind the source address( & port) in KAFKA messaging

Hi everyone,

            I am using camel KAFKA inside Apache KARAF and producing
messages to the KAFKA server. I have multiple interfaces configured in my
system and sending(producing) messages will happen only by using the first
interface *managmentserver1_local_interface* always. Same thing i tried
with camel-ftp in which i can choose the network interface by using the
name "*managmentserver1_traffic_interface*" and binding through the
*bindAddress* api which is introduced after 2.23. Is there any way to
configure the camel kafka component to select network interfaces? Currently
my machine has 2 network interfaces.

127.0.0.1   localhost localhost.localdomain localhost4
localhost4.localdomain4192.198.10.1 testserver1
managementserver1_local_interface192.199.11.2 testserver1
managementserver1_traffic_interface

I Went through the source code of kafka and found that internally it is
creating a socket which is used for transferring which will provide the
option to bind the source address.

private void configureSocketChannel(SocketChannel socketChannel, int
sendBufferSize, int receiveBufferSize)
            throws IOException {
        socketChannel.configureBlocking(false);
        Socket socket = socketChannel.socket();
        socket.setKeepAlive(true);
        if (sendBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
            socket.setSendBufferSize(sendBufferSize);
        if (receiveBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
            socket.setReceiveBufferSize(receiveBufferSize);
        socket.setTcpNoDelay(true);
    }

Note: There is an option to choose the network interface in camel-ftp
through an attribute bindAddress which allows us to bind the source
addressees(in case of multiple interfaces). We are using camel 2.25.2
Because we are planning to handle the traffic only through traffic
interface and oam activities through only management server local interface.

Also adding a route in OS level will help but adding a route will have the
below complexities.

    - It will affect other functionalities as OAM will have to route it to
the configured one and proceed further. This will introduce a hop
in-between the source and destination.

   - We are packaging the camel karaf inside the KARAF container which
doesn't have the permission to modify the routes from KARAF.

The reason I am asking in the KAFKA forum is because CAMEL is packaging the
apache-kafka clients inside camel.

Thanks,

M Shriram.