1

I am using camel KAFKA inside Apache KARAF and producing messages to 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 nterfaces? Currently my machine has 2 network interfaces.

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
192.198.10.1 testserver1 managementserver1_local_interface
192.199.11.2 testserver1 managementserver1_traffic_interface

Gone 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 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.23. Because we are planning to handle the traffic only through traffic interface and oam activities through only management server local interface.

Shriram
  • 4,343
  • 8
  • 37
  • 64
  • 1
    This is a great question, and I wish I knew the answer. I can't imagine that camel-kafka will support binding a client to a specific IP if the underlying Kafka runtime does not; and it seems from your inspection of the source that this function is not not exposed, right? – Kevin Boone Sep 15 '20 at 09:04
  • yes. This is not exposed. Gone through source code and found this. Obviously they are using socket to send the packets(message) so there is an option to bind source address. Same was addressed in camel-ftp by an api recently. Posted the same in camel-user forum but didn't get any replies till now. http://camel.465427.n5.nabble.com/binding-source-address-in-camel-kafka-td5882564.html – Shriram Sep 15 '20 at 09:06
  • 1
    Seems you've answered your own question ;) Looks like an opportunity to raise a feature request -- I can't imagine you're the only person that needs this facility. – Kevin Boone Sep 15 '20 at 09:07
  • Its just a normal thing because to handle the oam activities and traffic stuff we are having multiple interfaces. Not to affect traffic we are planning to route it through traffic interface only. – Shriram Sep 15 '20 at 09:09
  • 1
    You asked this same question last week. Kafka clients don't bind to ports and the code you've shown doesn't open any port, only configures the socket channel. If you have to configure routes, use the `route` command, not the hosts file – OneCricketeer Sep 15 '20 at 14:28
  • Yes. But that was too generic and removed the post. Thats why i have gone through the code and pasted here. Code pasted here doesn't bind any ports or address. I don't have permission do route as i am executing my application in karaf container. Also socket has the provision to bind source and bind with ports while transferring the packets. So i am checking for the provision to bind the port/address through some attributes(similar to bindAddress) which will inturn set the port/address while transferring. – Shriram Sep 16 '20 at 03:30

0 Answers0