当我发送给没有密钥的Kafka主题时,我已经通过了集成测试。但是,当我添加密钥时,我开始出现序列化错误。
org.apache.kafka.common.errors.SerializationException: Error deserializing key/value for partition topic-1 at offset 0
Caused by: org.apache.kafka.common.errors.SerializationException: Size of data received by IntegerDeserializer is not 4
Run Code Online (Sandbox Code Playgroud)
这是我的发送者类:
public class Sender {
private static final Logger LOG = LoggerFactory.getLogger(Sender.class);
@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
public void send() {
String topic = "topic";
String data = "data";
String key = "key";
LOG.info("sending to topic: '{}', key: '{}', data: '{}'", topic, key, data);
// does not work
kafkaTemplate.send(topic, key, data);
// works
// kafkaTemplate.send(topic, data);
} …Run Code Online (Sandbox Code Playgroud) 我试图用"服务器"和客户端创建一个简单的聊天程序,现在我的问题是程序在从服务器读取消息到客户端时阻塞,反之亦然.此示例解决了从客户端到服务器的消息问题.
我在服务器端的示例:
private Reader input;
private Writer output;
try {
server = new ServerSocket(this.port);
while (true) {
Socket connection = server.accept();
serverDisplay("We have a connection");
input = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
output = new BufferedWriter(new OutputStreamWriter(
connection.getOutputStream()));
int c;
StringBuffer sb = new StringBuffer();
// This is where it blocks, the input stream should return -1 at the end of the
// stream and break the loop, but it doesnt
while ((c = input.read()) != -1) {
sb.append((char) c);
} …Run Code Online (Sandbox Code Playgroud) 当我意识到输出重定向&>在脚本中不起作用时,我试图制作一个小脚本。如果我在终端写
dpkg -s firefox &> /dev/null
Run Code Online (Sandbox Code Playgroud)
或者
dpkg -s firefox 2>&1 /dev/null
Run Code Online (Sandbox Code Playgroud)
我没有输出,但是如果我将它插入到脚本中,它将显示输出。奇怪的是,如果我在脚本里面写
dpkg -s firefox 1> /dev/null
Run Code Online (Sandbox Code Playgroud)
或者
dpkg -s firefox 2> /dev/null
Run Code Online (Sandbox Code Playgroud)
命令的输出被抑制。我怎样才能同时抑制stderr和stdout?
我试图理解CompletableFuture,并遇到了2个方法,然后是ApplyAsync然后是Make.我试图了解这两者之间的区别.
CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
System.out.println(Thread.currentThread().getName() + " Printing hello");
return "Hello";
}).thenCompose((String s) -> {
return CompletableFuture.supplyAsync(() -> {
System.out.println(Thread.currentThread().getName() + " Adding abc");
return "abc "+s;});
}).thenApplyAsync((String s) -> {
System.out.println(Thread.currentThread().getName() + " Adding world");
return s + " World";
}).thenApplyAsync((String s) -> {
System.out.println(Thread.currentThread().getName() + " Adding name");
if (false) {
throw new RuntimeException("Oh no exception");
}
return s + " player!";
}).handle((String s, Throwable t) -> {
System.out.println(s != null ? s : "BLANK"); …Run Code Online (Sandbox Code Playgroud) 我有一个GroupUser实例列表String getGroup()和String getName()方法.我想返回Map<String, List<String>>键是组的位置,值是该组的名称列表.
如果我使用
Map<String, List<GroupUser>> groupUserList = users.stream()
.collect(Collectors.groupingBy(GroupUser::getGroup));
Run Code Online (Sandbox Code Playgroud)
返回 Map<String, List<GroupUser>>
我怎样才能Map<String, List<String>>直接获得