在camel kafka中发送消息时选择源ip地址

blmhpbnm  于 2021-06-04  发布在  Kafka
关注(0)|答案(0)|浏览(268)

我在apachekaraf中使用camel-kafka并向kafka服务器生成消息。我在系统中配置了多个接口,发送(生成)消息只能始终使用第一个接口managementserver1\u local\u接口。我在camel ftp上也做了同样的尝试,我可以使用名称“managementserver1\u traffic\u interface”来选择网络接口,并通过bindaddress api(在2.23之后引入)进行绑定。有没有办法配置camel kafka组件来选择网络接口?目前我的机器有两个网络接口。

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

查看了kafka的源代码,发现它正在内部创建一个用于传输的套接字,该套接字将提供绑定源地址的选项。

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);
    }

注意:在camel ftp中有一个选项可以通过bindaddress属性选择网络接口,该属性允许我们绑定源地址(如果有多个接口)。我们使用的是camel 2.23。因为我们计划只通过流量接口处理流量,而oam活动只通过管理服务器本地接口处理。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题