oleg
oleg

Reputation: 55

Redis Pub/Sub doesn't publish message

I'm using StackExchange.Redis .NET client for Redis (installed on Windows 7). Hostname - 127.0.0.1, port - 6379

Subscriber:

using (var connection = ConnectionMultiplexer.Connect(string.Format("{0}:{1},abortConnect=false,ConnectTimeout=10000", m_HostName, m_Port)))
{
   var sub = connection.GetSubscriber();
   sub.Subscribe("tasks", (channel, value) =>
   {
      // processing
   });
}

Publisher:

using (var connection = ConnectionMultiplexer.Connect(string.Format("{0}:{1},abortConnect=false,ConnectTimeout=10000", m_HostName, m_Port)))
{
   var subscriber = connection.GetSubscriber();
   Logger.Debug(subscriber.IsConnected().ToString());
   subscriber.Publish("tasks", message);
}

In logs I can see that subscriber is connected and there is no exception on this row:

subscriber.Publish("tasks", message); 

But subscriber doesn't catch any message and Redis Desktop Manager shows that DB is empty.

In redis cli the command PUBSUB CHANNELS displays next result, that means that channel exists:

  1. "tasks"
  2. "__Booksleeve_MasterChanged"

Also, I pushed string to DB and it was successfull:

var db = connection.GetDatabase();
db.StringSet("key","message");

Any ideas or suggestions?

Upvotes: 0

Views: 3005

Answers (1)

sebuseba
sebuseba

Reputation: 51

The connection of your subscriber will be disposed unless you block your client at the end of the using-statement. Therefore your client won't receive any pubsub messages after the using-statement.

Upvotes: 1

Related Questions