基本
一旦连接 ,你可以通过调用 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);
});