130. 动态编译
有一个 sample 应用程序使用 function 编译器从 configuration property 创建一个 function。香草“function-sample”也具有这种特征。还有一些脚本可以 run 来查看 run time 发生的编译。要运行这些示例,请转到scripts
目录:
cd scripts
另外,在本地启动 RabbitMQ 服务器(e.g. 执行rabbitmq-server
)。
启动 Function Registry Service:
./function-registry.sh
注册功能:
./registerFunction.sh -n uppercase -f "f->f.map(s->s.toString().toUpperCase())"
使用 Function 运行 REST 微服务:
./web.sh -f uppercase -p 9000
curl -H "Content-Type: text/plain" -H "Accept: text/plain" localhost:9000/uppercase -d foo
注册供应商:
./registerSupplier.sh -n words -f "()->Flux.just(\"foo\",\"bar\")"
使用该供应商运行 REST 微服务:
./web.sh -s words -p 9001
curl -H "Accept: application/json" localhost:9001/words
注册 Consumer:
./registerConsumer.sh -n print -t String -f "System.out::println"
使用 Consumer 运行 REST 微服务:
./web.sh -c print -p 9002
curl -X POST -H "Content-Type: text/plain" -d foo localhost:9002/print
Run Stream Processing 微服务:
首先注册流媒体字供应商:
./registerSupplier.sh -n wordstream -f "()->Flux.interval(Duration.ofMillis(1000)).map(i->\"message-\"+i)"
然后启动源(供应商),处理器(function)和 sink(consumer)应用程序(反向_):
./stream.sh -p 9103 -i uppercaseWords -c print
./stream.sh -p 9102 -i words -f uppercase -o uppercaseWords
./stream.sh -p 9101 -s wordstream -o words
输出将显示在 sink 应用程序的 console 中(每秒一条消息,转换为大写):
MESSAGE-0
MESSAGE-1
MESSAGE-2
MESSAGE-3
MESSAGE-4
MESSAGE-5
MESSAGE-6
MESSAGE-7
MESSAGE-8
MESSAGE-9
...