Spring Cloud 動(dòng)態(tài)編譯

2024-01-08 09:15 更新

有一個(gè)示例應(yīng)用程序,該應(yīng)用程序使用函數(shù)編譯器從配置屬性中創(chuàng)建函數(shù)。原始的“功能示例”也具有該功能。您可以運(yùn)行一些腳本來查看編譯在運(yùn)行時(shí)發(fā)生的情況。要運(yùn)行這些示例,請(qǐng)切換到scripts目錄:

cd scripts

另外,在本地啟動(dòng)RabbitMQ服務(wù)器(例如,執(zhí)行rabbitmq-server)。

啟動(dòng)功能注冊表服務(wù):

./function-registry.sh

注冊功能:

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

使用該功能運(yùn)行REST微服務(wù):

./web.sh -f uppercase -p 9000
curl -H "Content-Type: text/plain" -H "Accept: text/plain" localhost:9000/uppercase -d foo

注冊供應(yīng)商:

./registerSupplier.sh -n words -f "()->Flux.just(\"foo\",\"bar\")"

使用該供應(yīng)商運(yùn)行REST微服務(wù):

./web.sh -s words -p 9001
curl -H "Accept: application/json" localhost:9001/words

注冊消費(fèi)者:

./registerConsumer.sh -n print -t String -f "System.out::println"

使用該使用者運(yùn)行REST微服務(wù):

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

運(yùn)行流處理微服務(wù):

首先注冊流字供應(yīng)商:

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

然后啟動(dòng)源(供應(yīng)商),處理器(功能)和宿(消費(fèi)者)應(yīng)用程序(以相反的順序):

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

輸出將顯示在接收器應(yīng)用程序的控制臺(tái)中(每秒一條消息,轉(zhuǎn)換為大寫字母):

MESSAGE-0
MESSAGE-1
MESSAGE-2
MESSAGE-3
MESSAGE-4
MESSAGE-5
MESSAGE-6
MESSAGE-7
MESSAGE-8
MESSAGE-9
...
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)