开发者

Can different OPA apps share Databases?

I'm just investigating OPA and trying to make the leap from a traditional LAMP background, so here's my first of many newbie questions:

Can I have two OPA apps sharing the same database, say one which wr开发者_JAVA技巧ites into a database and another that reads from it?


Yes, it's certainly possible. A simple but complete example:

[db.opa]

database ./counter
db /counter : int
Counter = {{
  read() = /counter
  inc() = /counter <- read() + 1
}}

[db_read.opa]

server = one_page_server("Counter app", -> <>Counter value: {Counter.read()}</>)

[db_write.opa]

_ = Scheduler.timer(1000, -> Counter.inc())

Compile with:

 opa db_read.opa db.opa -o db_read.exe
 opa db_write.opa db.opa -o db_write.exe

Run the database server for database counter on port 5001:

 opa-db-server -b 127.0.0.1:5001 --db-local counter

Run the applications, connecting to this database:

 ./db_read.exe --db-remote 127.0.0.1:5001
 ./db_write.exe --db-remote 127.0.0.1:5001

The db_write app updates the counter every second. You can see that with the db_read app by visiting localhost:8080 (and refreshing the page).

Hope the Opa-DB experts will correct me if I got something wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜