'dotnet core Subscriber is not being triggered after Publishing
I'm working on a Redis(StackExchange.Redis) PUBSUB system in Dotnet core and everything works normally until after I publish to my channel. The subscriber simply won't ever be triggered.
Here is my code:
program.cs
public static void Main(string[] args)
{
_ = RunConsumer();
BuildWebHost(args).Run();
}
private static async Task RunConsumer()
{
LogWriter logger = new LogWriter();
IEnvironment envProvider = new EnvironmentProvider();
try
{
ICache cache = new Cache(envProvider);
IDataRepository dataRepo = new DatabaseRepository();
PubBusiness publisher = new PubBusiness();
await publisher.ImportData();
}
catch (Exception ex)
{
await logger.WriteLogErrorAsync($"Exception occurred", ex);
Environment.Exit(-1);
}
}
Publisher
// ... code that creates my key
// add my data to a batch and save it to redis
batchTasks.Add(batch.ListRightPushAsync("jobs", key));
batch.Execute();
Task.WaitAll(batchTasks.ToArray());
// publishing
ISubscriber sub = _connection.GetSubscriber();
await sub.PublishAsync("uploaded", key);
Subscriber
var db = _connection.GetDatabase();
ISubscriber sub = _connection.GetSubscriber();
// it will never pass here
await sub.SubscribeAsync("uploaded", async (channel, value) =>
{
var key = (await db.ListLeftPopAsync("jobs")).ToString();
// do my stuff here
});
Solution 1:[1]
Messaging disabled by default, follow the link for details BUT if short, just enter this command to redis cli to enable all:
CONFIG SET notify-keyspace-events KEA
https://redis.io/docs/manual/keyspace-notifications/#configuration
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Boryslav |