基本

一旦連線 ,你可以通過呼叫 ISubscriber.Publish 方法釋出訊息:

// grab an instance of an ISubscriber
var subscriber = connection.GetSubscriber();

// publish a message to the 'chat' channel
subscriber.Publish("chat", "This is a message")

消費者可以使用 ISubscriber.Subscribe 方法訂閱頻道。釋出者傳送的訊息將由傳遞給此方法的處理程式處理。

// grab an instance of an ISubscriber
var subscriber = connection.GetSubscriber();

// subscribe to a messages over the 'chat' channel
subscriber.Subscribe("chat", (channel, message) => {
    // do something with the message
    Console.WriteLine((string)message);
});