Skip to main content

Get message

Gets the next message from the stream

Function GetMessage(Val Connection, Val StreamID) Export

ParameterCLI optionTypeRequiredDescription
Connection-ArbitraryConnection object
StreamID-StringStream Identifier

Returns: Map Of KeyAndValue - Processing result

caution

NOCLI: this method is not available in CLI version


1C:Enterprise/OneScript code example
    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 = "DummyServerStream";

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");

NumberArray = New Array;
NumberArray.Add(1);
NumberArray.Add(10);
NumberArray.Add(100);

File = "https://hut.openintegrations.dev/test_data/document.docx";
OPI_TypeConversion.GetBinaryData(File);

TFN = GetTempFileName();
File.Write(TFN);

BinaryDataArray = New Array;
BinaryDataArray.Add(File); // How Data
BinaryDataArray.Add(TFN); // How path to file

Data = New Map;
Data.Insert("f_string" , "Test message");
Data.Insert("f_int32" , 123);
Data.Insert("f_int64" , 123);
Data.Insert("f_float" , 123.22000122070312);
Data.Insert("f_bool" , True);
Data.Insert("f_enum" , "ENUM_1");
Data.Insert("f_bytes" , File);
Data.Insert("f_strings", StingsArray);
Data.Insert("f_int32s" , NumberArray);
Data.Insert("f_bytess" , BinaryDataArray);
Data.Insert("f_sub" , New Structure("f_string", "Nested value"));

Result = OPI_GRPC.InitializeServerStream(Connection, Service, Method, Data);

If Not Result["result"] Then
Raise Result["error"];
Else
StreamID = Result["streamId"];
EndIf;

Result = OPI_GRPC.GetMessage(Connection, StreamID); // <---
Closing = OPI_GRPC.CloseStream(Connection, StreamID);
Result
{
"message": {
"f_bool": true,
"f_bools": [],
"f_bytes": {
"BYTES": "UEsDBBQABgAIAAAAIQAykW9XZgEAAKUFAAATAAgCW0..."
},
"f_bytess": [
{
"BYTES": "UEsDBBQABgAIAAAAIQAykW9XZgEAAKUFAAATAAgCW0..."
},
{
"BYTES": "UEsDBBQABgAIAAAAIQAykW9XZgEAAKUFAAATAAgCW0..."
}
],
"f_enum": "ENUM_1",
"f_enums": [],
"f_float": 123.220001220703,
"f_floats": [],
"f_int32": 123,
"f_int32s": [
1,
10,
100
],
"f_int64": 123,
"f_int64s": [],
"f_string": "Test message",
"f_strings": [
"one",
"two",
"three"
],
"f_sub": {
"f_string": "Nested value"
},
"f_subs": []
},
"result": true
}