Receive(Int32) Method
- Last UpdatedApr 08, 2026
- 1 minute read
Receives data from the underlying PubSub connection and blocks until data is available or the timeout has expired.
public PubSubMessage Receive(
int timeout
)
public:
PubSubMessage^ Receive(
int timeout
)
Parameters
- timeout
- The timeout value in milliseconds (0 means infinity).
Return Value
The PubSub received message status.
This method is not thread safe.
This command is used in conjunction with the blocking Subscribe(String,TimeSpan,Boolean) method and not the asynchronous Subscribe(String,TimeSpan,Boolean,Action<PubSubMessage>) method. If subscriptions are made with the asynchronous subscribe and then this method is called, an exception will be raised indicating incompatible usage of callback and blocking methods.
This method is useful if the application wants to process messages in a synchronous manner from a special processing thread. If processing of messages is expensive, the received message should be copied and handed off to a separate worker thread for processing.
Inline processing of received PubSub messages:
var connectionAccessor = new GlobalPubSubConnectionAccessor(); var connection = connectionAccessor.GlobalConnection; var messageBuilder = new MessageBuilder(); // Synchronous processing of messages. while(receiving) { var message = connection.Receive(0); ProcessMessage(message); } // Asynchronous processing of messages. while(receiving) { var message = connection.Receive(0).Copy(); Task.Run(() => ProcessMessage(message)); }var connectionAccessor = new GlobalPubSubConnectionAccessor();
var connection = connectionAccessor.GlobalConnection;
var messageBuilder = new MessageBuilder();
// Synchronous processing of messages.
while(receiving)
{
var message = connection.Receive(0);
ProcessMessage(message);
}
// Asynchronous processing of messages.
while(receiving)
{
var message = connection.Receive(0).Copy();
Task.Run(() => ProcessMessage(message));
}