Spring For Apache Kafka 2.1.0 和 1.3.2 发布

栏目: 软件资讯 · 发布时间: 6年前

内容简介:Spring for Apache Kafka 2.1.0 已发布,同时发布的还有 1.3.2 和 2.0.2 维护版本,包含重要的 Bug 修复。 2.1.0 版本的主要将 kafka-clients 库升级到 1.0.0,以及一些改进: Sometimes, when a message can’...

Spring for Apache Kafka 2.1.0 已发布,同时发布的还有 1.3.2 和 2.0.2 维护版本,包含重要的 Bug 修复。

2.1.0 版本的主要将 kafka-clients 库升级到 1.0.0,以及一些改进:

  • Sometimes, when a message can’t be processed, you may wish to stop the container so the condition can be corrected and the message re-delivered. The framework now provides the ContainerStoppingErrorHandler for record listeners and ContainerStoppingBatchErrorHandler for batch listeners.

  • The KafkaAdmin now supports increasing partitions when a NewTopic bean is detected with a larger number of partitions than currently exist on the topic.

  • StringJsonMessageConverter and JsonSerializer/JsonDeserializer now pass and consume type information in Headers. This allows multiple types to be easily sent/received on the same topic:

@SpringBootApplication
public class Kafka21Application {

    public static void main(String[] args) {
        SpringApplication.run(Kafka21Application.class, args)
            .close();
    }

    @Bean
    public ApplicationRunner runner(KafkaTemplate<Object, Object> template) {
        return args -> {
            template.send(MessageBuilder.withPayload(42)
                    .setHeader(KafkaHeaders.TOPIC, "blog")
                    .build());
            template.send(MessageBuilder.withPayload("43")
                    .setHeader(KafkaHeaders.TOPIC, "blog")
                    .build());
            Thread.sleep(5_000);
        };
    }

    @Bean
    public StringJsonMessageConverter converter() {
        return new StringJsonMessageConverter();
    }

    @Component
    @KafkaListener(id = "multi", topics = "blog")
    public static class Listener {

        @KafkaHandler
        public void intListener(Integer in) {
            System.out.println("Got an int: " + in);
        }

        @KafkaHandler
        public void stringListener(String in) {
            System.out.println("Got a string: " + in);
        }

    }

}

Got an int: 42
Got a string: 43

  •  the JsonSerializer and JsonDeserializer can be configured using kafka properties for the producer/consumer. 

更多详情请查阅发行主页。


【声明】文章转载自:开源中国社区 [http://www.oschina.net]


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

当下的冲击

当下的冲击

道格拉斯•洛西科夫 (Douglas Rushkoff) / 孙浩 赵晖 / 中信出版社 / 2013-10-1 / 59.00元

这是一个并不符合人本能的社会…… 为什么我们不应该更注重生活的质量而非速度? 为什么我们不用面对面的交流代替冷冰冰电脑屏幕上的文字代码? 为什么我们不可以选择一个虽然有缺陷但有血有肉的人类社会,而非一个虽趋于完美但冷漠的数字世界? 在当下的冲击面前,你正变得越来越弱智:你没有了自己的独特空间,你过多地相信真人秀节目,你成了数字化产品的奴隶并得了数字化精神病,你的生物钟也被打......一起来看看 《当下的冲击》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具