PubSubConnection Class
- Last UpdatedApr 08, 2026
- 4 minute read
[CLSCompliant(false)]
public sealed class PubSubConnection : IPubSubConnection, ISharedPubSubConnection
[CLSCompliant(false)]
public ref class PubSubConnection sealed : public IPubSubConnection, ISharedPubSubConnection
The PubSub connection is thread-safe. However, it should be noted that Disconnect is not supported from callbacks as this may cause a deadlock.
If an application exists in the system "main", it may publish on a topic such as "main.myappinfo". All system primitive data types are supported but not complex objects. Another application can now subscribe to "main.myappinfo" and receive this information. If another piece of data was published on "main.myappinfo.info2", the subscribing application would also receive this as it is subscribed to the parent topic "main.myappinfo". There are two types of subscription supported: blocking and non-blocking subscriptions. With callback subscriptions, the application creates a callback PubSubCallbackMethod delegate. When a topic arrives on the callback, this delegate is called. With blocking subscriptions, the application must call
There are several methods for connecting to PubSub.
Note: Unless otherwise indicated, PubSub will attempt to maintain the connection and reconnect automatically.
The following connection syntax is supported:
Connect: A unique .Net PubSubConnection with a shared engine connection. Not used with GlobalConnection. No auto reconnect.
Connect(String,Int32): A unique .Net PubSubConnection object with a unique engine connection. Not used with GlobalConnection. No auto reconnect.
There is a global PubSub connection available for use. This connection is shared between objects, threads, and even different libraries, including libraries written in other languages, for example, C. It can be easily accessed and reduces the load on the PubSub system if used throughout the application, but it should not be cleaned up or disconnected as this may affect other code. The following example shows a global connection being used:
PubSubConnection.GlobalConnection.Publish("main.mytopic.i", i, PubSubHeaderData.PS_NORMAL_DATA);
Shared connections to the engine are supported through the GlobalConnection member and through the Connect function when no parameters are provided. At the .NET level, these functions provide different functionality, GlobalConnection is a shared .NET PubSub object, whereas Connect is used to connect a unique PubSubConnection object up to a shared connection to the PubSub system. These functions operate simiarly to a telephone system in a home or office (ignoring the fact that everyone can hear each other's conversations). A group of people speaking with a speaker phone would be similar to the GlobalConnection, one connection object shared by many. A group of people with separate handsets but the same telephone connection would be similar to the Connect function, many connection objects, one connection. A group of people with separate handsets and different telephone numbers in a conference call would be similar to non-shared PubSub connections, many connection objects, many connections. This final case can be achieved by using a non-global connection and either
Note: Shared connections are also sharing subscriptions and delivery queues. If callbacks are used for subscriptions, then message delivery can be made thread or object specific by having different callbacks for each thread or object; however, if blocking receive is used, then the threads must be aware that they may receive messages subscribed to by other threads and may not receive messages that they have subscribed to because they may be delivered to another thread calling
PubSub supports an asynchronous connection model as well as synchronous. With asynchronous connections the application tells the PubSub system to maintain a connection as much as it can. PubSub will inform the application when the connection comes alive and goes away using the topic "pubsub.status.connection". Subscriptions can be done any time and will be maintained, but
PubSubConnection.GlobalConnection.OpenConnection();
int i = 5;
PubSubConnection.GlobalConnection.Publish("main.mytopic.i", i, PubSubHeaderData.PS_NORMAL_DATA);
PubSubConnection PS = new PubSubConnection();
PS.Connect();
int i = 5;
PS.Publish("main.mytopic.i", i, PubSubHeaderData.PS_NORMAL_DATA);
PubSubConnection PS = new PubSubConnection();
PS.Connect("myApp", 50000);
// Could also use PS.OpenConnection("myApp");
int i = 5;
PS.Publish("main.mytopic.i", i, PubSubHeaderData.PS_NORMAL_DATA);
System.Object
OASySDNA.Common.PubSub.PubSubConnection
Reference
PubSubConnection Members
OASySDNA.Common.PubSub Namespace
Receive
Receive
Subscribe
OpenConnection
OpenConnection
Receive
Publish
