1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2026-04-30 20:49:04 +02:00
Files
OpenIntegrations/docs/en/examples/GRPC/InitializeClientStream.txt
T

73 lines
2.1 KiB
Plaintext
Vendored

Address = "https://grpcb.in:9001";
Proto1 = "https://hut.openintegrations.dev/test_data/grpcbin_with_import.proto"; // String, path to file or URL
Proto2 = "https://hut.openintegrations.dev/test_data/mt.proto"; // String, path to file or URL
Scheme = New Map;
Scheme.Insert("main.proto" , Proto1); // Primary
Scheme.Insert("my_types.proto", Proto2); // For import in primary
Parameters = OPI_GRPC.GetConnectionParameters(Address, Scheme);
Tls = OPI_GRPC.GetTlsSettings(True);
Service = "grpcbin.GRPCBin";
Method = "DummyClientStream";
Connection = OPI_GRPC.CreateConnection(Parameters, Tls);
If Not OPI_GRPC.IsConnector(Connection) Then
Raise Connection["error"];
EndIf;
StingsArray = New Array;
StingsArray.Add("one");
StingsArray.Add("two");
StingsArray.Add("three");
Data = New Map;
Data.Insert("f_string" , "Test message");
Data.Insert("f_int32" , 123);
Data.Insert("f_bool" , True);
Data.Insert("f_strings", StingsArray);
Data.Insert("f_sub" , New Structure("f_string", "Nested value"));
Result = OPI_GRPC.InitializeClientStream(Connection, Service, Method); // <---
If Not Result["result"] Then
Raise Result["error"];
Else
StreamID = Result["streamId"];
EndIf;
FinalMessage = Undefined;
Counter = 0;
While True Do
CurrentSend = OPI_GRPC.SendMessage(Connection, StreamID, Data);
Counter = Counter + 1;
If Not CurrentSend["result"] Then
Error = CurrentSend["error"];
If Error = "Timeout" Then
Continue;
ElsIf Error = "Closed" Then
FinalMessage = OPI_GRPC.GetMessage(Connection, StreamID);
Break;
Else
Raise StrTemplate("%1 (sent messages %2)", Error, Counter);
EndIf;
Else
If Counter = 10 Then
Completion = OPI_GRPC.CompleteSend(Connection, StreamID);
FinalMessage = OPI_GRPC.GetMessage(Connection, StreamID);
Break;
EndIf;
EndIf;
EndDo;