Skip to content

Commit aaa55f8

Browse files
author
Hinne Stolzenberg
committed
Initial commit
0 parents  commit aaa55f8

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
buf
2+
stargate
3+
__pycache__
4+
venv

grpc_example.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from __future__ import print_function
2+
3+
import logging
4+
import os
5+
6+
# Generated code needs the following aliases to be done manually.
7+
import collections.abc
8+
collections.Iterable = collections.abc.Iterable
9+
collections.Mapping = collections.abc.Mapping
10+
collections.MutableSet = collections.abc.MutableSet
11+
collections.MutableMapping = collections.abc.MutableMapping
12+
13+
# GRPC generated code imports.
14+
import grpc
15+
from stargate.supplier.item.v1beta1 import supplier_item_service_pb2_grpc
16+
from stargate.supplier.item.v1beta1 import supplier_item_service_pb2
17+
from stargate.type.v1 import uuid_pb2
18+
19+
# Set grpc log verbosity level.
20+
os.environ["GRPC_VERBOSITY"] = "DEBUG"
21+
22+
# Address to connect to.
23+
ADDR2 = "10.200.0.70:80"
24+
25+
# example uuid = "C3ECA1AE-BF47-4C14-AF8D-4991306C98AA" (stage).
26+
def list_items(stub):
27+
test = supplier_item_service_pb2.ListItemsRequest(
28+
supplier_uuid = uuid_pb2.UUID(value = "C3ECA1AE-BF47-4C14-AF8D-4991306C98AA")
29+
)
30+
31+
for item in stub.ListItems(test):
32+
print(item.supplier_item_identifier)
33+
34+
def create_item(stub):
35+
req = supplier_item_service_pb2.CreateItemRequest(
36+
supplier_uuid = uuid_pb2.UUID(value = "C3ECA1AE-BF47-4C14-AF8D-4991306C98AA"),
37+
supplier_item_identifier = "this has to be unique!1",
38+
item_no = "not unique, but needs to be the steps item no",
39+
price = 124284.23,
40+
stock = 1230,
41+
)
42+
43+
# No Feedback for now unless there is an error.
44+
res = stub.CreateItem(req)
45+
print(res)
46+
47+
def update_item(stub):
48+
req = supplier_item_service_pb2.UpdateItemRequest(
49+
supplier_uuid = uuid_pb2.UUID(value = "C3ECA1AE-BF47-4C14-AF8D-4991306C98AA"),
50+
supplier_item_identifier = "this has to be unique!1",
51+
item_no = "not unique, but needs to be the steps item no", # Optional on this request.
52+
price = 124284.23, # Optional on this request.
53+
stock = 1230, # Optional on this request.
54+
)
55+
56+
# No Feedback for now unless there is an error.
57+
res = stub.UpdateItem(req)
58+
print(res)
59+
60+
def delete_item(stub):
61+
req = supplier_item_service_pb2.UpdateItemRequest(
62+
supplier_uuid = uuid_pb2.UUID(value = "C3ECA1AE-BF47-4C14-AF8D-4991306C98AA"),
63+
supplier_item_identifier = "this has to be unique!1",
64+
)
65+
66+
# No Feedback for now unless there is an error.
67+
res = stub.DeleteItem(req)
68+
print(res)
69+
70+
def run():
71+
with grpc.insecure_channel(ADDR2) as channel:
72+
stub = supplier_item_service_pb2_grpc.SupplierItemServiceStub(channel)
73+
print("-------------- ListItems --------------")
74+
list_items(stub)
75+
print("-------------- CreateItem --------------")
76+
create_item(stub)
77+
print("-------------- UpdateItem --------------")
78+
update_item(stub)
79+
print("-------------- DeleteItem --------------")
80+
delete_item(stub)
81+
print("-------------- DONE --------------")
82+
83+
if __name__ == "__main__":
84+
logging.basicConfig()
85+
run()

0 commit comments

Comments
 (0)