132. 动态编译

有一个示例应用程序,它使用函数编译器从配置属性中创建函数。原始的“功能 samples”也具有该功能。您可以运行一些脚本来查看编译在运行时发生的情况。要运行这些示例,请转到scripts目录:

cd scripts

另外,在本地启动 RabbitMQ 服务器(例如,执行rabbitmq-server)。

启动功能注册表服务:

./function-registry.sh

注册功能:

./registerFunction.sh -n uppercase -f "f->f.map(s->s.toString().toUpperCase())"

使用该功能运行 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"

使用该使用者运行 REST 微服务:

./web.sh -c print -p 9002
curl -X POST -H "Content-Type: text/plain" -d foo localhost:9002/print

运行流处理微服务:

首先注册流字供应商:

./registerSupplier.sh -n wordstream -f "()->Flux.interval(Duration.ofMillis(1000)).map(i->\"message-\"+i)"

然后启动源(供应商),处理器(功能)和宿(Consumer)应用程序(以相反的 Sequences):

./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

输出将显示在接收器应用程序的控制台中(每秒一条消息,转换为大写字母):

MESSAGE-0
MESSAGE-1
MESSAGE-2
MESSAGE-3
MESSAGE-4
MESSAGE-5
MESSAGE-6
MESSAGE-7
MESSAGE-8
MESSAGE-9
...