1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2026-05-18 09:51:28 +02:00
Files
OpenIntegrations/docs/en/examples/ClickHouse/OpenGRPCStream.txt
T
Vitaly the Alpaca (bot) b5b50d0777 Main build (Jenkins)
2026-02-15 00:51:39 +03:00

60 lines
1.8 KiB
Plaintext
Vendored

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;
Completion = OPI_ClickHouse.CompleteGRPCSending(Connection, StreamID);
FinalMessage = OPI_ClickHouse.GetGRPCMessage(Connection, StreamID);
OPI_GRPC.CloseConnection(Connection);