问题描述
我正在 Dotnet 核心中开发 Redis(StackExchange.Redis) PUBSUB 系统,一切正常,直到我发布到我的频道。订阅者根本不会被触发。
这是我的代码:
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);
}
}
出版商
// ... 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);
订阅者
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
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)