介绍 Spring Cloud Stream - Spring Cloud Stream中文文档(三)

本文为Spring Cloud Stream文档的中文翻译,原文地址:
https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.3.RELEASE/reference/html/spring-cloud-stream.html
另外,Spring Cloud 版本:Hoxton.SR3,支持的 Spring Boot 版本:2.2.5.RELEASE

Spring Cloud Stream 是一个构建消息驱动的微服务框架,基于 Spring Boot 来创建独立的生产级的 Spring 应用,并使用 Spring Integration 连接消息代理。为一些供应商的消息中间件产品提供了个性化的自动化配置实现,并引入了发布-订阅、消费组、分区这三个核心概念。

将 spring-cloud-stream 的依赖添加到应用程序中,你可以连接到由spring-cloud-stream-binder暴露的消息代理(稍后会详细介绍),并且你可以通过java.util.function.Function执行传入的消息,实现需求。

这是一个简单的示例:

@SpringBootApplication
public class SampleApplication {

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

    @Bean
	public Function<String, String> uppercase() {
	    return value -> value.toUpperCase();
	}
}

和相应的测试

@SpringBootTest(classes =  SampleApplication.class)
@Import({TestChannelBinderConfiguration.class})
class BootTestStreamApplicationTests {

	@Autowired
	private InputDestination input;

	@Autowired
	private OutputDestination output;

	@Test
	void contextLoads() {
		input.send(new GenericMessage<byte[]>("hello".getBytes()));
		assertThat(output.receive().getPayload()).isEqualTo("HELLO".getBytes());
	}
}

本章示例代码:https://github.com/dudiao/spring-cloud-stream-example

我的最新文章会先发到公众号【读钓的YY】上,欢迎关注!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值