使用Azure Service Bus从IBus进行SchedulePublish

时间:2017-06-16 17:18:56

标签: c# azure azureservicebus masstransit

我们目前将MassTransit与RabbitMQ结合使用,现在我想添加对Azure Service Bus的支持,我想使用本机Azure Service Bus调度API。我很高兴看到MassTransit支持它,但我无法弄清楚它是如何工作的(我们目前不通过MassTransit API使用消息调度,而是使用Hangfire调度的自定义代码)。

Consume上下文调度消息时,documentation很明确,但不太清楚的是如何从IBus上下文中执行此操作。

Consume上下文中,我只需要一个消息实例和一个延迟,我可以调用context.SchedulePublish。但是从IBus开始,我只有ScheduleSend可用(无Publish),并且每个重载都需要Uri作为其目的地。我不知道从哪里得到Uri或者它的含义是什么。我实际上并没有拥有目的地,我只想延迟一段时间的发布事件。

在下面的代码中,只会消费和记录“已发布”和“消费者”消息。与ScheduleSend一起发送的“已计划”消息无错误地发送但未收到。

https://gist.github.com/JulianRooze/bdbabce8c0b62f62dacde3b755777aa0

IBus启动和ScheduleSend的日志输出如下:

2017-06-16 19:11:09 [Debug] Subscribing Consumer: "ConsoleApp4.TestConsumer" (using default constructor)
2017-06-16 19:11:09 [Debug] Starting bus hosts...
2017-06-16 19:11:09 [Debug] Starting receive transport: sb://<omitted>.servicebus.windows.net/test_queue
2017-06-16 19:11:09 [Debug] Starting receive transport: sb://<omitted>.servicebus.windows.net/DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4?express=true&autodelete=300
2017-06-16 19:11:09 [Debug] Connecting receive transport: sb://<omitted>.servicebus.windows.net/test_queue
2017-06-16 19:11:09 [Debug] Connecting receive transport: sb://<omitted>.servicebus.windows.net/DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4?express=true&autodelete=300
2017-06-16 19:11:09 [Debug] Queue: "test_queue" ("dead letter")
2017-06-16 19:11:09 [Debug] Topic: "ConsoleApp4/Test" ("")
2017-06-16 19:11:09 [Debug] Updating subscription: "test_queue" ("ConsoleApp4/Test" -> "sb://<omitted>.servicebus.windows.net/test_queue")
2017-06-16 19:11:09 [Debug] Subscription: "test_queue" ("ConsoleApp4/Test" -> "sb://<omitted>.servicebus.windows.net/test_queue")
2017-06-16 19:11:09 [Debug] Creating queue client for sb://<omitted>.servicebus.windows.net/test_queue
2017-06-16 19:11:09 [Debug] Creating message receiver for sb://<omitted>.servicebus.windows.net/test_queue
2017-06-16 19:11:10 [Debug] Creating queue "DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4"
2017-06-16 19:11:11 [Debug] Queue: "DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4" ("express, dead letter")
2017-06-16 19:11:11 [Debug] Creating queue client for sb://<omitted>.servicebus.windows.net/DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4?express=true&autodelete=300
2017-06-16 19:11:11 [Debug] Creating message receiver for sb://<omitted>.servicebus.windows.net/DESKTOPJULIAN_ConsoleApp4_bus_ghroyyr3bcyx635xbdkmjsiqr4?express=true&autodelete=300
Started
2017-06-16 19:11:21 [Debug] GetSendEndpoint: sb://<omitted>.servicebus.windows.net/MassTransit.Scheduling/ScheduleMessage--ConsoleApp4/Test--
2017-06-16 19:11:21 [Debug] Topic: "MassTransit.Scheduling/ScheduleMessage--ConsoleApp4/Test--" ("")
2017-06-16 19:11:21 [Debug] SEND sb://<omitted>.servicebus.windows.net/MassTransit.Scheduling/ScheduleMessage--ConsoleApp4/Test-- 37090000-990b-00ff-95a9-08d4b4dab5db MassTransit.Scheduling.ScheduleMessage<ConsoleApp4.Test>

由MassTransit配置的队列/ topcs:

The queues/topcs as configured by MassTransit

0 个答案:

没有答案