Subscribe(ISharedPubSubConnection,String) Method
- Last UpdatedApr 08, 2026
- 1 minute read
Subscribes to the indicated topic using a blocking receive with infinite timeout.
[Extension()]
[CLSCompliant(false)]
public static IPubSubSubscription Subscribe(
ISharedPubSubConnection connection,
string topic
)
[Extension()]
[CLSCompliant(false)]
public:
static IPubSubSubscription^ Subscribe(
ISharedPubSubConnection^ connection,
String^ topic
)
Parameters
- connection
- The ISharedPubSubConnection to extend.
- topic
- The topic string to subscribe to.
This version of subscribing is useful if it is necessary for the application to process messages in a synchronous manner from a special processing thread or a pool of such threads.
If this routine is called after any subscriptions are made with callbacks, then an exception will be raised indicating the use of incompatible subscription semantics.
using (var subscription = connection.Subscribe("mySystem.MyTopic"))
{
var topic = default(String);
var buffer = default(PubSubBuffer);
var headerData = default(PubSubHeaderData);
subscription.Receive(ref topic, ref buffer, ref headerData);
// Process buffer.
}
using (var subscription = connection.Subscribe("mySystem.MyTopic"))
{
var topic = default(String);
var buffer = default(PubSubBuffer);
var headerData = default(PubSubHeaderData);
subscription.Receive(ref topic, ref buffer, ref headerData);
// Process buffer.
}