apache zookeeper kafka路径(apache zookeeper kafka path)
我有一个应用程序可以设置与kafka主题的风暴连接。 我在我们的组织中从另一个类似的回购中模仿的设置具有如下属性:
zookeeper.connect=127.0.0.1:2181/kafka_0.9
我发现使用这个设置,在我的本地开发环境中,我的应用程序在尝试创建风暴喷口时会抛出一个错误。 该错误追踪到对
getNumPartitions
的调用。 详细的错误日志如下:org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /brokers/topics/Moment_2018_01_16_07_59_08/partitions at org.apache.zookeeper.KeeperException.create(KeeperException.java:111) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1590) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:214) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:203) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107) ~[curator-client-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.pathInForeground(GetChildrenBuilderImpl.java:199) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:191) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:38) ~[curator-framework-2.5.0.jar:na] at storm.kafka.DynamicBrokersReader.getNumPartitions(DynamicBrokersReader.java:91) ~[storm-kafka-0.9.6.jar:na]
当我从属性中取出尾部
/kafka_0.9
时,如下所示:zookeeper.connect=127.0.0.1:2181
然后这个错误消失。 我的推测是我们组织的代码在staging和prod环境中有一个特定的路径
/kafka_0.9
设置(可能指定使用kafka 0.9)。 但我想知道如何在本地开发环境中创建此路径以及与我们的分段和产品环境保持一致? 目前我docker-compose.yml
对zookeeper&kafka具有以下功能:zookeeper: image: myorg/zookeeper:3.4.8 ports: - "2181:2181" kafka: image: myorg/kafka:kafka-0.10 hostname: myapp.docker ports: - "9092:9092" environment: EXPOSED_HOST: myapp.docker KAFKA_PORT: 9092 KAFKA_ADVERTISED_PORT: 9092 ZOOKEEPER_PORT_2181_TCP_ADDR: zookeeper ZOOKEEPER_PORT_2181_TCP_PORT: 2181 ZOOKEEPER_IP: zookeeper links: - zookeeper extra_hosts: - "localhost:0.0.0.0"
I have an application that sets up storm connection to kafka topics. The settings I imitated from another similar repo in our org has a property like the following:
zookeeper.connect=127.0.0.1:2181/kafka_0.9
I've found that with this setting, in my local dev environment, my app throws an error when it tries to create storm spout. The error is traced to a call to
getNumPartitions
. The detailed error log is the following:org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /brokers/topics/Moment_2018_01_16_07_59_08/partitions at org.apache.zookeeper.KeeperException.create(KeeperException.java:111) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.KeeperException.create(KeeperException.java:51) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1590) ~[zookeeper-3.4.6.jar:3.4.6-1569965] at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:214) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:203) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:107) ~[curator-client-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.pathInForeground(GetChildrenBuilderImpl.java:199) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:191) ~[curator-framework-2.5.0.jar:na] at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:38) ~[curator-framework-2.5.0.jar:na] at storm.kafka.DynamicBrokersReader.getNumPartitions(DynamicBrokersReader.java:91) ~[storm-kafka-0.9.6.jar:na]
When I take out the trailing
/kafka_0.9
from the property like so:zookeeper.connect=127.0.0.1:2181
Then this error disappears. My speculation is that the code for our org has a specific path
/kafka_0.9
setup in our staging & prod environment (probably to specify using kafka 0.9). But I wonder how I can create this path in local dev environment as well just to be consistent with our staging & prod environments? Currently mydocker-compose.yml
has the following for zookeeper & kafka:zookeeper: image: myorg/zookeeper:3.4.8 ports: - "2181:2181" kafka: image: myorg/kafka:kafka-0.10 hostname: myapp.docker ports: - "9092:9092" environment: EXPOSED_HOST: myapp.docker KAFKA_PORT: 9092 KAFKA_ADVERTISED_PORT: 9092 ZOOKEEPER_PORT_2181_TCP_ADDR: zookeeper ZOOKEEPER_PORT_2181_TCP_PORT: 2181 ZOOKEEPER_IP: zookeeper links: - zookeeper extra_hosts: - "localhost:0.0.0.0"
原文:https://stackoverflow.com/questions/48293445
最满意答案
试试这段代码:
let parameters: [String:AnyObject] = [ "Key" : "somekey", "cid" : 23, "timestamp" : 1732998762, "number": 1124, ] do { let theJSONData = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions(rawValue: 0)) let theJSONText = NSString(data: theJSONData, encoding: NSASCIIStringEncoding) print(theJSONText) } catch { }
Try this code :
let parameters: [String:AnyObject] = [ "Key" : "somekey", "cid" : 23, "timestamp" : 1732998762, "number": 1124, ] do { let theJSONData = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions(rawValue: 0)) let theJSONText = NSString(data: theJSONData, encoding: NSASCIIStringEncoding) print(theJSONText) } catch { }
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
警告:如果由于某种原因您必须使用JSON字符串工作,这是将JSON字符串转换为字典的方便方法。 但是,如果您有JSON 数据可用,您应该使用数据 ,而不使用字符串。 Swift 3 func convertToDictionary(text: String) -> [String: Any]? { if let data = text.data(using: .utf8) { do { return try JSONSerialization.jsonObje ...
-
简单干净的方式将JSON字符串转换为Swift中的对象(Simple and clean way to convert JSON string to Object in Swift)[2022-11-17]
这里有一些技巧如何从简单的例子开始。 考虑你有以下的JSON数组字符串(类似于你的): var list:Array= [] // left only 2 fields for demo struct Business { var id : Int = 0 var name = "" } var jsonStringAsArray = "[\n" + "{\n" + "\"id\":72,\ ... -
我会说你正在尝试的是误入歧途。 您不应该使用CoreData来存储字符串。 您应该使用CoreData,因为它应该被用作关系数据库。 创建表,然后使用JSON字典以填充它们的方式填充这些表。 这就是说:类NSJSONSerialization有一个方法将数组或字典转换为NSData,以及一种将NSData转换为数组或字典的方法。 因此,要创建字符串,请将NSDictionary转换为NSData,从中创建NSString,存储字符串。 要将字符串转回NSDictionary,请从中创建NSData对象,使用 ...
-
在Swift中,如何将具有任何类型值的字典转换为JSON字符串(In Swift, how to convert a dictionary with any-type values to a JSON string)[2023-01-29]
试试这段代码: let parameters: [String:AnyObject] = [ "Key" : "somekey", "cid" : 23, "timestamp" : 1732998762, "number": 1124, ] do { let theJSONData = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions(rawV ... -
字符串不是AnyObject类型。 对象是引用类型 ,但swift中的String具有值语义 。 然而, 字符串可以是Any类型,所以下面的代码可以工作。 我建议你阅读Swift中的引用类型和值语义类型; 它是一个微妙但重要的区别,它与大多数其他语言所期望的不同,其中String通常是引用类型(包括目标C)。 let jsonObject: [String: Any] = [ "firstname": "aaa", "lastname": "sss", ...
-
如果仔细观察jsonObject(with:options:)返回的内容,您将看到它是[String: Any]或[Any] ,具体取决于您的JSON。 因此, jsonString实际上存储了一个[String: Any] ,甚至认为编译器认为它是Any类型: let jsonString = try? JSONSerialization.jsonObject(with: data!, options: []) print(jsonString!) 如果你试图将它传递给convertToDicti ...
-
您可以使用以下函数从SwiftyJSON对象获取int或字符串:.stringValue,.intValue,.boolValue,.doubleValue等。 You can get an int or a string from SwiftyJSON objects by using the following functions: .stringValue, .intValue, .boolValue, .doubleValue etc.
-
将字典转换为Json(Convert dictionary to Json)[2021-11-08]
我认为你得到一个空结果的主要原因是因为你返回的是Result ,而不是你填充的dictionary变量。 另外,如果collListItem是IEnumerable(因为它似乎是,因为你用foreach循环它),你不需要逐项构建字典。 尝试: Dictionary dictionary=collListItem.ToDictionary(c=>c["ID"],c=>c["Title"]); return Json(dictionary,JsonReque ...