在 MassTransit 中使用随机数据安排定期消息

Schedule recurring message with random data in MassTransit

我想在 MassTransit 中安排重复消息,但每次消息发送到队列时我都想生成相同的随机数据。

目前我有这样的代码

        var scheduleEndPoint = await _bus.GetSendEndpoint(new Uri($"{BusConstants.RabbitMqUri}/quartz"));
        await scheduleEndPoint.ScheduleRecurringSend(
            new Uri($"{BusConstants.RabbitMqUri}/{ConfigurationManager.AppSettings["ArticlesImportServiceQueue"]}"),
            new ArticlesImportRecurringSchedule(),
            ArticlesImportNotificationMapper.MapFromFile());

问题是 ArticlesImportNotificationMapper.MapFromFile() 只被第一次调用。有什么建议吗?

预定消息就是预定消息——在发送时不会以任何方式修改。

如果您需要生成随机数据,或者修改消息的内容,我建议您安排一个单独的重复消息,例如GenerateAndSendCommand,并创建一个接收该消息的消费者,然后在生成并插入随机数据等之后,将实际的 CommandWithRandomData 发送给配置的消费者