我有关于正确配置kafka侦听器属性的问题- 听众和做广告的听众。
在我的配置中,我正在设置以下道具:
import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { Network } from '@ionic-native/network';
import { Subject } from 'rxjs/Subject';
import { NotificationService } from './notification-service';
@Injectable()
export class NetworkService {
info: any = {
connected: true,
type: "none"
};
disconnectSubscription: any;
connectSubscription: any;
private infoConnection = new Subject<any>();
infoConnection$ = this.infoConnection.asObservable();
constructor(
private network: Network,
private platform: Platform,
private notificationService: NotificationService,
) {
this.disconnectSubscription = this.network.onDisconnect().subscribe(() => {
this.sendStatus();
});
this.connectSubscription = this.network.onConnect().subscribe(() => {
this.sendStatus();
});
}
sendStatus() {
if (this.platform.is("cordova")) {
setTimeout(() => {
this.info = {
connected : this.isConnected(),
type: this.getConnectionType()
}
this.infoConnection.next(this.info);
}, 3000);
}
}
isConnected() {
if (this.platform.is("cordova")) {
let hasConnection = this.network.type == "none" || this.network.type == 'unknown' ? false : true;
return hasConnection;
} else {
return true;
}
}
getConnectionType() {
if (this.platform.is("cordova")) {
return this.network.type;
} else {
return true
}
}
客户端使用listeners=SASL_PLAINTEXT://:9092
advertised.listeners=SASL_PLAINTEXT://u-kafkatst-kafkadev-5.sd.xxx.com:9092
连接。我是否需要在listener和advertised.listeners中具有相同的值。这里的u-kafkatst-kafkadev-5.sd.xxx.com:9092
是dns记录,它指向运行kafka代理的主机。
在什么情况下我想保持它们不变?
谢谢!
答案 0 :(得分:2)
如果要执行除直接连接到同一网络上的代理之外的任何操作,则advertised.listeners
属性非常重要。如果您使用的是Docker,Kubernetes,IaaS(AWS,GCP等),则需要公开外部地址,以便客户端知道要连接到的位置。
This article对其进行了深入解释。