Have [SBT plugin][sbt-plugin] installed
- [Create a new project][create-project] in IDEA ( File > New Project ...)
- Make sure you select a maven module
// CQS (Command-Query Separation) | |
// Bertrand Meyer devised the CQS principle | |
// It states that every method should either be a command that performs an action, or a | |
// query that returns data to the caller, but not both. In other words, asking a question | |
// should not change the answer. More formally, methods should return a value only if they | |
// are referentially transparent and hence possess no side effects. | |
// | |
// Example: | |
public class CustomerService |
#Intro
Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3
Kotlin project website is at kotlin.jetbrains.org.
All the codes here can be copied and run on Kotlin online editor.
Let's get started.
import java.io.IOException; | |
import java.util.Properties; | |
import kafka.server.KafkaConfig; | |
import kafka.server.KafkaServerStartable; | |
public class KafkaLocal { | |
public KafkaServerStartable kafka; | |
public ZooKeeperLocal zookeeper; |
- What do Etcd, Consul, and Zookeeper do? | |
- Service Registration: | |
- Host, port number, and sometimes authentication credentials, protocols, versions | |
numbers, and/or environment details. | |
- Service Discovery: | |
- Ability for client application to query the central registry to learn of service location. | |
- Consistent and durable general-purpose K/V store across distributed system. | |
- Some solutions support this better than others. | |
- Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state. | |
- Centralized locking can be based on this K/V store. |
public static <A, B> B foldLeft(Stream<A> iterable, B identity, BiFunction<B, A, B> bf) { | |
return foldLeft(iterable.iterator(), identity, bf); | |
} | |
public static <A, B> B foldLeft(Iterable<A> iterable, B identity, BiFunction<B, A, B> bf) { | |
return foldLeft(iterable.iterator(), identity, bf); | |
} | |
public static <A, B> B foldLeft(Iterator<A> iterator, B identity, BiFunction<B, A, B> bf) { | |
B result = identity; |
import io.vertx.core.Vertx | |
import io.vertx.ext.web.Router | |
import za.co.koperfontein.amapogo.safetyq.mongo.MONGO_ENTRY_PAGE_ENABLE_DISABLE | |
import za.co.koperfontein.amapogo.safetyq.mongo.MONGO_ENTRY_PAGE_GET | |
import za.co.koperfontein.amapogo.safetyq.mongo.MONGO_ENTRY_PAGE_VALUES_UPDATE | |
// Example usage | |
class PageHttpRoutes(router: Router, vertx: Vertx): RegisterHttpRoutes(router, vertx) { | |
override fun registerRoutes() { |
object test { | |
import scalaz.zio._ | |
type UserID = String | |
case class UserProfile(name: String) | |
// The database module: | |
trait Database { | |
val database: Database.Service |
// Porting of https://gist.github.com/jdegoes/dd66656382247dc5b7228fb0f2cb97c8 | |
typealias UserID = String | |
data class UserProfile(val name: String) | |
// The database module: | |
interface DatabaseService { | |
suspend fun dbLookup(id: UserID): UserProfile | |
suspend fun dbUpdate(id: UserID, profile: UserProfile) | |
} |
I've been working with Apache Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥