Skip to main content

Subscribe

Subscribe to a topic in the PUB/SUB scheme

Function Subscribe(Val Connection, Val Prefix) Export

ParameterCLI optionTypeRequiredDescription
Connection--connArbitraryAddIn object with an open connection or port
Prefix--prefixStringRequired prefix (topic) of messages to receive
Returns

Map Of KeyAndValue - Processing result

1C:Enterprise/OneScript code example
// Host
Port = 5555;
ServerObject = OPI_ZeroMQ.BindPortPub(Port);

If Not OPI_ZeroMQ.IsConnectorObject(ServerObject) Then
Raise OPI_Tools.JSONString(ServerObject);
EndIf;

// Client
Address = "tcp://127.0.0.1:5555";
ClientObject = OPI_ZeroMQ.CreateConnectionSub(Address);

If Not OPI_ZeroMQ.IsConnectorObject(ClientObject) Then
Raise OPI_Tools.JSONString(ClientObject);
EndIf;

Prefix = "topic.";
Message = StrTemplate("%1ZeroMQ_SUB_%2", Prefix, Format(CurrentDate(), "DF=yyyyMMddhhmmss"));
Data = GetBinaryDataFromString(Message);

Result = OPI_ZeroMQ.Subscribe(ClientObject, Prefix);
Result
{
"result": true
}