Skip to content
This repository has been archived by the owner on Dec 7, 2024. It is now read-only.

Commit

Permalink
server-connection
Browse files Browse the repository at this point in the history
  • Loading branch information
naomijub committed Apr 25, 2023
1 parent d955c00 commit e186b53
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
all:
fmt:
lein cljfmt fix

kibit:
lein kibit --replace

lint: fmt kibit

proto:
protoc --clojure_out=grpc-client,grpc-server:src --proto_path=resources resources/service.proto

all: proto lint

run:
lein run

jar:
lein uberjar

test:
lein test
14 changes: 14 additions & 0 deletions kreya/grpc/com/xtdb/protos/GrpcApi/SubmitTx-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"txOps": [
{
"put": {
"document": "Via Security"
}
},
{
"put": {
"document": "Rustic Plastic Sausages Graphic Interface incubate"
}
}
]
}
12 changes: 12 additions & 0 deletions kreya/grpc/com/xtdb/protos/GrpcApi/SubmitTx.krop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"details": {
"methodFqn": "com.xtdb.protos.GrpcApi.SubmitTx"
},
"requests": [
{
"location": "SubmitTx-request.json"
}
],
"operationType": "unary",
"invokerName": "grpc"
}
2 changes: 1 addition & 1 deletion resources/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ message StatusResponse {

service GrpcApi {
rpc Status (Empty) returns (StatusResponse);
rpc submit_tx (com.xtdb.protos.SubmitRequest) returns (com.xtdb.protos.SubmitResponse);
rpc SubmitTx (com.xtdb.protos.SubmitRequest) returns (com.xtdb.protos.SubmitResponse);

}
6 changes: 3 additions & 3 deletions src/com/xtdb/protos/GrpcApi/client.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
:metadata metadata}]
(p/then (send-unary-params input params) (fn [_] (invoke-unary client desc output))))))

(defn submit_tx
([client params] (submit_tx client {} params))
(defn SubmitTx
([client params] (SubmitTx client {} params))
([client metadata params]
(let [input (async/chan 1)
output (async/chan 1)
desc {:service "com.xtdb.protos.GrpcApi"
:method "submit_tx"
:method "SubmitTx"
:input {:f com.xtdb.protos/new-SubmitRequest :ch input}
:output {:f com.xtdb.protos/pb->SubmitResponse :ch output}
:metadata metadata}]
Expand Down
8 changes: 4 additions & 4 deletions src/com/xtdb/protos/GrpcApi/server.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
;-----------------------------------------------------------------------------
(defprotocol Service
(Status [this param])
(submit_tx [this param]))
(SubmitTx [this param]))

(def GrpcApi-service-name "com.xtdb.protos.GrpcApi")

(defn- Status-dispatch
[ctx request]
(Status ctx request))
(defn- submit_tx-dispatch
(defn- SubmitTx-dispatch
[ctx request]
(submit_tx ctx request))
(SubmitTx ctx request))

(def ^:const rpc-metadata
[{:pkg "com.xtdb.protos" :service "GrpcApi" :method "Status" :method-fn Status-dispatch :server-streaming false :client-streaming false :input pb->Empty :output new-StatusResponse}
{:pkg "com.xtdb.protos" :service "GrpcApi" :method "submit_tx" :method-fn submit_tx-dispatch :server-streaming false :client-streaming false :input pb->SubmitRequest :output new-SubmitResponse}])
{:pkg "com.xtdb.protos" :service "GrpcApi" :method "SubmitTx" :method-fn SubmitTx-dispatch :server-streaming false :client-streaming false :input pb->SubmitRequest :output new-SubmitResponse}])
3 changes: 3 additions & 0 deletions src/gxtdb/service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

(deftype GrpcAPI [xtdb-node]
api/Service
(SubmitTx [_this _request]
{:status 200
:body {:tx-time "time" :tx-id 3}})
(Status
[_this _request]
(let [status (xt/status xtdb-node)]
Expand Down

0 comments on commit e186b53

Please sign in to comment.