Skip to main content

Send GRPC data

Sends part of the data (additional QueryInfo) to the stream

Function SendGRPCData(Val Connection, Val StreamID, Val Data, Val WaitNext = False) Export

ParameterCLI optionTypeRequiredDescription
Connection-ArbitraryGRPC connection object
StreamID-StringStream Identifier
Data-ArbitraryA string, collection, binary data, or file path to send
WaitNext-BooleanFlag for waiting for the next messages after the current one
Returns

Map Of KeyAndValue - Processing result

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
URL = "http://localhost:9101";
Login = "bayselonarrend";
Password = "12we...";

Authorization = New Structure(Login, Password);

ConnectionSettings = OPI_ClickHouse.GetGRPCConnectionSettings(URL, Authorization);
Connection = OPI_ClickHouse.CreateGRPCConnection(ConnectionSettings);

Result = OPI_ClickHouse.OpenGRPCStream(Connection);

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

QueryText = "INSERT INTO events_stream_test FORMAT JSONEachRow";
DataFormat = "JSON";
CurrentDate = Date("20260101100000");

Counter = 0;
While Counter < 5 Do

Record = New Structure;
Record.Insert("id" , Counter + 1);
Record.Insert("timestamp" , CurrentDate);
Record.Insert("user_id" , 100 + Counter);
Record.Insert("event_type" , "stream_test");
Record.Insert("payload" , "{}");

Record = OPI_Tools.JSONString(Record) + Chars.LF;

Last = Counter = 4;

If Counter = 0 Then

Request = OPI_ClickHouse.GetRequestSettings(QueryText, "default", , Record, DataFormat);
CurrentSend = OPI_ClickHouse.SendGRPCMessage(Connection, StreamID, Request, , Not Last);
Else
CurrentSend = OPI_ClickHouse.SendGRPCData(Connection, StreamID, Record, Not Last); // <---
EndIf;

If Not CurrentSend["result"] Then

Error = CurrentSend["error"];

If Error <> "Timeout" Then
Raise OPI_Tools.JSONString(CurrentSend);
EndIf;

EndIf;

Counter = Counter + 1;

EndDo;
Result
{
"result": true,
"streamId": "5441dd70-168e-4273-baca-9564889bdea9"
}