This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% @doc Safely delegate a task to another process. | |
%% The task can spawn linked processes without implicitly | |
%% bringing down the caller process. | |
%% EXIT reasons are captured and propagated to caller. | |
%% @end | |
safe_delegate(TaskFun) when is_function(TaskFun, 0) -> | |
Parent = self(), | |
TaskRef = make_ref(), | |
{Pid, Ref} = | |
erlang:spawn_monitor( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule BrodDemo do | |
@kafka_hosts [localhost: 9092] | |
@topic "brod-demo-group-subscriber-koc" | |
@produce_delay_seconds 2 | |
## bootstrap demo with partition producers producing sequence numbers | |
## every DEFAULT seconds. | |
def bootstrap() do | |
bootstrap(@produce_delay_seconds) | |
end | |
## bootstrap demo subscrirber and a number of sequence number producers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% generated code, do not edit! | |
-module(kpro_schema). | |
-export([get/2]). | |
get(produce_request, V) when V >= 0, V =< 2 -> | |
[{acks,int16}, | |
{timeout,int32}, | |
{topic_data,{array,[{topic,string}, | |
{data,{array,[{partition,int32}, | |
{record_set,records}]}}]}}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% Copyright (c) 2014-2017, Klarna AB | |
%%% | |
%%% Licensed under the Apache License, Version 2.0 (the "License"); | |
%%% you may not use this file except in compliance with the License. | |
%%% You may obtain a copy of the License at | |
%%% | |
%%% http://www.apache.org/licenses/LICENSE-2.0 | |
%%% | |
%%% Unless required by applicable law or agreed to in writing, software | |
%%% distributed under the License is distributed on an "AS IS" BASIS, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /tmp | |
# get code | |
rm -rf kafka_protocol | |
git clone https://github.com/klarna/kafka_protocol.git -b hack-in-magic-v2-decode | |
rm -rf brod | |
git clone https://github.com/klarna/brod.git -b hack-in-magic-v2-decode | |
# compile code | |
COMP="/usr/kastlex/erts-9.3.3.9/bin/erlc -I brod/include -I kafka_protocol/include" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
TOPIC="$1" | |
PARTITION_MIN="$2" | |
PARTITION_MAX="$3" | |
echo '{"partitions":[' | |
for i in $(seq ${PARTITION_MIN} ${PARTITION_MAX}); do | |
echo -n "{\"topic\": \"${TOPIC}\",\"partition\": $i}" | |
if [ $i -lt $PARTITION_MAX ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
usage() { | |
echo "Usage: $0 -t <topic-name> -p <partition-number> -r <replicas> --throttle <bytes/s> [-z <zookeeper-host>] [--reorder-replicas]" | |
echo " where <replicas> is a comma separated node IDs in preferred order, or in natural order if --reorder-replicas is given" | |
echo "Example: $0 -t foo -p 0 -r 1,2,3 --throttle 10000000" | |
exit "$1" | |
} | |
REORDER_REPLICAS_LIST="NO" | |
while [[ $# -gt 0 ]]; do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Demoting leader is a necessary step before moving replicas off that node otherwise follower fetchers may crash due to a kafka bug. | |
# This script makes use of replica-reassign.sh script to demote a node from preferred leader in the given topic-partition's replicas list | |
# It then forces a preferred leader election for this topic-partition. | |
usage() { | |
echo "Usage: $0 -t <topic-name> -p <partition-number> -n <node-id> [-z <zookeeper-host>]" | |
echo "For example, if topic 'foo' partition 0 has replicas list [0,1,2]" | |
echo "Running command '$0 -t foo -p 0 -n 0' will change the order to [1,2,0]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lein-exec | |
;; this script requires clojure, lein with lein-exec plugin | |
;; ref: https://github.com/kumarshantanu/lein-exec | |
;; it accepts first one argument as the smile-format json file path | |
;; decodes the smile json and print the plain json to console | |
(use '[leiningen.exec :only (deps)]) | |
(deps '[[cheshire "5.10.0"]]) | |
(require '[cheshire.core :refer :all]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
## EMQX can only start with longname (https://erlang.org/doc/reference_manual/distributed.html) | |
## The host name part of EMQX's node name has to be static, this means we should either | |
## pre-assign static IP for containers, or ensure containers can communiate with each other by name | |
## this is why a docker network is created, and the containers's names have a dot. | |
NET='my.net' |
OlderNewer