我使用以下代码写入Kafka:
String partitionKey = "" + System.currentTimeMillis();
KeyedMessage<String, String> data = new KeyedMessage<String, String>(topic, partitionKey, payload);
Run Code Online (Sandbox Code Playgroud)
我们使用的是Kafka的0.8.1.1版本.
有可能当多个线程正在写入时,其中一些(具有不同的有效负载)使用相同的分区键写入,因此Kafka会覆盖这些消息(由于相同的partitionKey)?
让我们朝这个方向思考的文档是:http: //kafka.apache.org/documentation.html#compaction
似乎某处有一个非常愚蠢的错误,因为以下 hello-world 程序对我不起作用。
import com.google.common.io.BaseEncoding;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
String hello = "hello";
junit.framework.Assert.assertEquals(
hello.getBytes(),
BaseEncoding.base64().decode(
BaseEncoding.base64().encode(hello.getBytes())
)
);
Run Code Online (Sandbox Code Playgroud)
我什至试过 hello.getBytes("ISO-8859-1")
我错过了什么?
给定一个字符串,找到另一个包含输入字符串的所有组合的字符串.
示例:
如果输入字符串="23",那么它的组合将是["22","23","32","33"],
包含所有上述组合的字符串之一将是"22233233",但这不会是最短的.最短的将是"22332".
算法应该足够通用,以适用于任何大小的输入字符串.(假设输入不是太大,输出将保持在正常的int/string/jvm等大小.还假设输入字符串只有英文字母的字母数字字符)
我尝试了以下算法,但它似乎没有工作:
1)找到string = ["22","23","32","33"]的所有组合
2)构建前缀图[2:{22,23},3:{32,33}]
3)从前缀映射中的任何组合和查找后缀开始.
示例:从22开始,其后缀为2从前缀映射中,对应的值2为22和23.选择此处的一个单词,这不是当前选取的单词,因此它将给出23
4)将拾取的单词的后缀添加到当前字符串(这给出223)
5)重复.所以我会得到223的后缀= 3来自前缀图,3:{32,33}选择任何一个,比如说32加到当前字符串得到2232
6)如果没有其他内容匹配,则追加到当前字符串.这给出了223233
但是,答案应该是22332,因为这是最短的.
这是我到目前为止编写的完整代码:
public class TextContainingAllPermutations
{
static String input = "ABC";
public static void main (String args[])
{
int suffixLen = input.length()-1;
Set<String> combinations = getCombinations();
while (suffixLen > 0 && combinations.size() > 1)
{
Map<String, List<String>> suffixToWords = getPrefixMap(combinations, suffixLen);
String someWordsString = combinations.iterator().next();
combinations.remove(someWordsString);
Set<String> combinations2 = new HashSet<String>();
while (combinations.size() > 0)
{
String suffix = someWordsString.substring(someWordsString.length()-suffixLen);
List<String> words = …Run Code Online (Sandbox Code Playgroud) 下面的命令每秒生成输出60秒.
sar -n DEV 1 60 | grep lo
Run Code Online (Sandbox Code Playgroud)
如果我将其重定向到文件,则文件sar.log会连续更新,即每秒更新一次
sar -n DEV 1 60 > sar.log &
Run Code Online (Sandbox Code Playgroud)
但是,只要管道然后将其重定向到文件,它就会在文件sar.log完成后填充,即60秒后填充文件.
sar -n DEV 1 60 | grep lo > sar.log &
Run Code Online (Sandbox Code Playgroud)
如何grep和重定向到文件,以便日志文件连续更新,即每秒
我可以使用除grep之外的其他东西,如果它有助于我选择某些内容并每秒重定向到一个文件.