Subscribe
Subscribe to a topic in the PUB/SUB scheme
- Parameters
- Advanced call ?
Function Subscribe(Val Connection, Val Prefix) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Connection | --conn | Arbitrary | ✔ | AddIn object with an open connection or port |
| Prefix | --prefix | String | ✔ | Required prefix (topic) of messages to receive |
Returns
Map Of KeyAndValue - Processing result
| Parameter | Description |
|---|---|
| dontwait | Creates a background job and returns its data (for 1C and OneScript only) |
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
}