Skip to main content

Get message

Receives an incoming message from the queue or waits for a new one

Function GetMessage(Val Connection, Val Timeout = 10000) Export

ParameterCLI optionTypeRequiredDescription
Connection-ArbitraryConnection, See CreateConnection
Timeout-NumberMessage receive timeout (in ms.)
Returns

BinaryData - Received message

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
Address = "wss://127.0.0.1:8443";
NeedProxy = True;
NeedTLS = True;

Headers = New Map;
Headers.Insert("X-Trace-Id", "OPI-WS-TEST");

If NeedTls Then
TLSSettings = OPI_WebSocket.GetTlsSettings(True);
EndIf;

If NeedProxy Then

ProxyAddress = "127.0.0.1";
ProxyPort = "8071";
ProxyType = "http";

ProxtUser = "proxyuser";
ProxyPassword = "12we...";

ProxySettings = OPI_AddIns.GetProxySettings(ProxyAddress
, ProxyPort
, ProxyType
, ProxtUser
, ProxyPassword);

EndIf;

Connection = OPI_WebSocket.CreateConnection(Address, TLSSettings, ProxySettings, Headers);

Message = "echo-text-" + Format(CurrentDate(), "DF=yyyyMMddhhmmss");

If OPI_WebSocket.IsClientObject(Connection) Then

// Sending a message to the ECHO server
Sending = OPI_WebSocket.SendTextMessage(Connection, Message);

// Skipping all responses from the server until the last one
While True Do

LastMessage = OPI_WebSocket.GetMessage(Connection, 3000); // <----

If LastMessage["result"] Then
Result = LastMessage;
Else
Break;
EndIf;

EndDo;

Else
Result = Connection;
EndIf;
Result
{
"data": {
"type": "echo",
"payload": "echo-text-20260526033752",
"tls": true,
"timestamp": "2026-05-26T12:37:52.888Z"
},
"result": true,
"type": "text"
}