kellanburket / franz Goto Github PK
View Code? Open in Web Editor NEWA Kafka Client for Swift
License: MIT License
A Kafka Client for Swift
License: MIT License
I'm testing your kafka client
I don' t really know kafka but i have to plug to it from iOS Application.
I tried your client in a local mode :
I set up local kafka using https://kafka.apache.org/documentation.html#quickstart
in swift code i use
BioKafkaInterface(ip: "127.0.0.1", port: 2181, clientId: "", groupId: "test-consumer-group", partition: 0, topic: "test");
Where BioKafkaInterface is :
import Foundation
import ReactiveCocoa
@objc class BioKafkaInterface: NSObject, BioCommunicator, HighLevelConsumerDelegate {
let cluster : Cluster
init(ip:String, port:Int, clientId:String, groupId:String, partition:Int, topic:String) {
print("init ip string")
self.cluster = Cluster(brokers:[(ip, Int32(port))], clientId:clientId);
super.init()
self.cluster.getHighLevelConsumer(topic, partition: Int32(partition), groupId: groupId, delegate:self)
}
func read(size:UInt) -> Signal<[Int8], NSError> {
return Signal.empty
}
func write(data:[Int8]) -> SignalProducer<Int, NSError> {
return SignalProducer.empty;
}
func consumerDidReturnMessage(message: Message, offset: Int64) {
print(NSString(data: message.value, encoding: NSUTF8StringEncoding))
}
func consumerIsReady(consumer: Consumer) {
print("Consummer is ready")
if let highLevelConsumer = consumer as? HighLevelConsumer {
print("\(highLevelConsumer.broker?.description)")
highLevelConsumer.poll()
}
}
func shouldCommitOffset(topic: String, partition: Int32, offset: Int64) -> Bool {
print("shouldCommitOffset \(topic, partition, offset)")
return true
}
func shouldAttachOffsetMetadata(topic: String, partition: Int32, offset: Int64) -> String? {
print("shouldAttachOffsetMetadata \(topic, partition, offset)")
return "toto"
}
func offsetDidCommit(topic: String, partition: Int32, offset: Int64) {
print("offsetDidCommit \(topic, partition, offset)")
}
func offsetCommitDidFail(topic: String, partition: Int32, offset: Int64, errorId: Int16, errorDescription: String) {
print("offsetCommitDidFail \(topic, partition, offset, errorId, errorDescription)")
}
func shouldRetryFailedOffsetCommit(topic: String, partition: Int32, offset: Int64, errorId: Int16, errorDescription: String) -> Bool {
print("shouldRetryFailedOffsetCommit \(topic, partition, offset, errorId, errorDescription)")
return true;
}
func fetchDidFail(
topic: String,
partition: Int32,
errorId: Int16,
errorDescription: String
) {
print("fetchDidFail \(topic, partition, errorId, errorDescription)");
}
func shouldRetryFailedFetch(
topic: String,
partition: Int32,
errorId: Int16,
errorDescription: String
) -> Bool {
print("shouldRetryFailedFetch \(topic, partition, errorId, errorDescription)");
return true
}
func topicPartitionLeaderNotFound(topic: String, partition: Int32) {
print("topicPartitionLeaderNotFound \(topic, partition) ");
}
}
The error in my log are :
INPUT STREAM STATUS: End
Zero Lenth Response
Log from zookeeper :
INFO Accepted socket connection from /127.0.0.1:49591 (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2016-03-08 11:20:46,397] WARN Exception causing close of session 0x0 due to java.io.IOException: Unreasonable length = 1915578226 (org.apache.zookeeper.server.NIOServerCnxn)
[2016-03-08 11:20:46,397] INFO Closed socket connection for client /127.0.0.1:49591 (no session established for client) (org.apache.zookeeper.server.NIOServerCnxn)
Have you any idea what's going on there?
Co you have a solution, or an alternative to use kafka client
I Implemented my franz consumer following the step but for some reasons consumer gets data without problem but on other run or build get exception in thread
on this line let start = prefix(upTo: startIndex + first)
please help me to get how to resolve it.
Here in my code
`class KafkaViewModel: ObservableObject {
@published var receivedMessages: [String] = []
let cluster: Cluster
let consumer: Consumer
init() {
self.cluster = Cluster(brokers: [("localhost", 9092)], clientId: "data")
self.consumer = self.cluster.getConsumer(topics: ["data-grid"], groupId: "data")
self.cluster.sendMessage("data-grid", message: "Grid data")
print("hello")
self.consumer.listen { [weak self] message in
DispatchQueue.main.async {
if let messageString = String(data: message.value, encoding: .utf8) {
print(messageString)
self?.receivedMessages.append(messageString)
} else {
print("Error: Failed to decode message data as UTF-8 string")
}
}
}
// No need to subscribe separately; topics are provided during consumer creation
// Example of sending a message (move this to appropriate place)
// self.cluster.sendMessage("quickstart-events", message: "Hello world! 2")
}
}`
I tried to sent a large message(1-2MB) and didn't work. I believe that happen because of "max.request.size" property. I looked in code after this property, or where i can put it, but i didn't figure it out. It's possible to send a message bigger than 1-2MB? If yes, where i have to put that property?
Thanks
Consumer not listening for messages at all
I am trying to access consumer by cluster as shown below:
let consumer = self.cluster.getConsumer
Currently the APIs are designed for 0.9.0. The current APIs should be tested against 1.1.0 and updated if needed
Currently there is a lot of boilerplate code in the APIs types. With Swift 4's Codable
protocols, we should create our own Encoder
and Decoder
for the Kafka protocol and let the compiler synthesise the rest for each type.
Is there support for SASL_SSL and SCRAM login in this library? Cannot find any.
Franz uses path in a non standard way. This trips gatekeeper when trying to install an application that includes Franz.
https://developer.apple.com/library/content/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG207
The solution is to change the following
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
and remove
OTHER_LDFLAGS
FRAMEWORK_SEARCH_PATHS
Do you have any plans to update this for Swift 3.0 and conform it to the Swift PM structure? I'd be happy to help.
It should be possible to call Consumer.listen
multiple times and have each callback get called every time a message is consumed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.