Masstransit - 安排支持多租户的定期消息

时间:2017-01-25 12:09:16

标签: multi-tenant masstransit

我想将Masstransit调度API用于多租户应用程序。我需要为每个租户发送重复的消息。

var schedule1 = new MySchedule("1 * * * * ?", "Tenant 1");
var schedule2 = new MySchedule("6 * * * * ?", "Tenant 2");

endPoint.Result.ScheduleRecurringSend(sendToUri, schedule1, new OrderCommand
{
    Id = Guid.NewGuid().ToString(),
    Name = "Tenant 1"
});

endPoint.Result.ScheduleRecurringSend(sendToUri, schedule2, new OrderCommand
{
    Id = Guid.NewGuid().ToString(),
    Name = "Tenant 2"
});


public class MySchedule : DefaultRecurringSchedule
{
    public MySchedule(string cronExpression, string description)
    {
        CronExpression = cronExpression;
        Description = description;
    }
}

问题是调度程序使用类名“MyScheduler”作为作业名称,并且不能使用MyScheduler发送两个重复的消息。有没有办法用Masstransit调度API实现多租户?

1 个答案:

答案 0 :(得分:1)

将构造函数中的ScheduleId和/或ScheduleGroup(对于您的MySchedule类)更改为特定于租户,并且它将更改Quartz使用的标识符。

public class MySchedule : DefaultRecurringSchedule
{
    public MySchedule(string cronExpression, string description, string tenantId)
    {
        CronExpression = cronExpression;
        Description = description;

        ScheduleId = "MyScheduleForTenant" + tenantId;
    }
}