1661838120
A swift implementation of Kafka for producing and consuming from event streams.
This works by wrapping the librdkafka C library.
The latest version of SwiftKafka requires Swift 5.0 or later. You can download this version of the Swift binaries by following this link.
Add the SwiftKafka
package to the dependencies within your application’s Package.swift
file. Substitute "x.x.x"
with the latest SwiftKafka
release.
.package(url: "https://github.com/IBM-Swift/SwiftKafka.git", from: "x.x.x")
Add SwiftKafka
to your target's dependencies:
.target(name: "example", dependencies: ["SwiftKafka"]),
import SwiftKafka
To use SwiftKafka you will need to install the librdkafka
package:
brew install librdkafka
Install librdkafka from the Confluent APT repositories - see instructions here (following steps 1 and 2 to add the Confluent package signing key and apt repository), and then install librdkafka:
sudo apt install librdkafka
To experiment locally, you can set up your own Kafka server to produce/consume from.
On macOS you can follow this guide on Kafka Installation using Homebrew to run a local server.
On Linux, you can follow this guide for a manual install on Ubuntu.
The KafkaConfig
class contains your configuration settings for a KafkaConsumer
/KafkaProducer
.
The class is initialized with default values which can then be changed using the helper functions. For example, to enable all logging you would set the debug variable:
let config = KafkaConfig()
config.debug = [.all]
Alternatively, you can access the configuration dictionary directly on the KafkaConfig
object:
let config = KafkaConfig()
config["debug"] = "all"
The list of configuration keys and descriptions can be found in the librdkafka CONFIGURATION.md.
When you pass this class to a producer/consumer, a copy is made so further changes to the instance will not affect existing configurations.
The KafkaProducer
class produces messages to a Kafka server.
You can initialize a KafkaProducer
using a KafkaConfig
instance or with the default configuration.
The producer sends a KafkaProducerRecord
with the following fields:
The send()
function is asynchronous. The result is returned in a callback which contains a KafkaConsumerRecord
on success or a KafkaError
on failure.
The following example produces a message with the value "Hello World" to a "test" topic of a Kafka server running on localhost.
do {
let producer = try KafkaProducer()
guard producer.connect(brokers: "localhost:9092") == 1 else {
throw KafkaError(rawValue: 8)
}
producer.send(producerRecord: KafkaProducerRecord(topic: "test", value: "Hello world", key: "Key")) { result in
switch result {
case .success(let message):
print("Message at offset \(message.offset) successfully sent")
case .failure(let error):
print("Error producing: \(error)")
}
}
} catch {
print("Error creating producer: \(error)")
}
The KafkaConsumer
class consumes messages from a Kafka server.
You can initialize a KafkaConsumer
using a KafkaConfig
instance or with the default configuration.
You can then subscribe to topics using subscribe()
. This will distribute the topic partitions evenly between consumers with the same group id. If you do not set a group id, a random UUID will be used.
Alternatively to can use assign()
to manually set the partition and offset for the consumer.
Both subscribe()
and assign()
are asynchronous and will return immediately, however they may take up to sessionTimeoutMs (Default 10 seconds) * 2 before the consumer completely connects.
To consume messages from Kafka you call poll(timeout:)
. This will poll Kafka, blocking for timeout
seconds. When it completes, it returns an array of KafkaConsumerRecord
with the following fields:
When you have finished consuming, you can call close()
to close the connection and unassigns the consumer. The unassigned partitions will then be rebalanced between other consumers in the group. If close()
is not called, the consumer will be closed when the class is deallocated.
The following example consumes and print all unread messages from the "test" topic of the Kafka server.
do {
let config = KafkaConfig()
config.groupId = "Kitura"
config.autoOffsetReset = .beginning
let consumer = try KafkaConsumer(config: config)
guard consumer.connect(brokers: "localhost:9092") == 1 else {
throw KafkaError(rawValue: 8)
}
try consumer.subscribe(topics: ["test"])
while(true) {
let records = try consumer.poll()
print(records)
}
} catch {
print("Error creating consumer: \(error)")
}
Author: Kitura
Source Code: https://github.com/Kitura/SwiftKafka
1592668860
In this tutorial, we’ll read about the Android SDK Manager. We will see what is SDK manager in Android and why and how it is important for Android. So, SDK stands for Software Development Kit, which is a collection of software tools required. SDK basically helps Android to download tools and recent versions of Android. Every time a new Android version is released, along with it is released an SDK corresponding to it. This SDK must be installed by the developers for the devices.
What is SDK Manager?
A Software development kit is a set of tools required for the development of applications for Android. It also ensures that the progress of App development goes as flat as pancakes. We need SDK irrespective of the language we are using. Android SDK comes wrapped up with the Android Studio these days. An Android SDK separates the tools, platforms and other components into packages. These can be downloaded from the SDK Manager.
#android tutorials #android sdk manager #android sdk manager download #android sdk tools #android studio sdk manager #sdk download #sdk manager #sdk tools
1600430400
Swift is a fast and efficient general-purpose programming language that provides real-time feedback and can be seamlessly incorporated into existing Objective-C code. This is why developers are able to write safer, more reliable code while saving time. It aims to be the best language that can be used for various purposes ranging from systems programming to mobile as well as desktop apps and scaling up to cloud services.
Below here, we list down the 10 best online resources to learn Swift language.
(The list is in no particular order)
#developers corner #free online resources to learn swift language #learn swift #learn swift free #learn swift online free #resources to learn swift #swift language #swift programming
1609999986
A thoroughly researched list of top Swift developers with ratings & reviews to help find the best Swift development companies around the world.
#swift development service providers #best swift development companies #top swift development companies #swift development solutions #top swift developers #swift
1594193714
Want to create a native iOS application for your Startup?
Hire Dedicated Swift Developers for end-to-end services like development, migration, upgrade, testing, and support & maintenance. Trust HourlyDeveloper.io our Swift development team for iOS device apps that are high on performance and security.
Consult with experts:- https://bit.ly/2C5M6cz
#hire dedicated swift developers #swift developers #swift development company #swift development services #swift development #swift
1580832840
This Apache Kafka Tutorial - Kafka Tutorial for Beginners will help you understand what is Apache Kafka & its features. It covers different components of Apache Kafka & it’s architecture. So, the topics which we will be discussing in this Apache Kafka Tutorial are:
Why Learn Apache Kafka?
Kafka training helps you gain expertise in Kafka Architecture, Installation, Configuration, Performance Tuning, Kafka Client APIs like Producer, Consumer and Stream APIs, Kafka Administration, Kafka Connect API and Kafka Integration with Hadoop, Storm and Spark using Twitter Streaming use case.
#apache #kafka #web-development #apache-kafka