2017-03-06 15 views
1

我一直在研究基於消息傳遞啓動一些工作者角色的應用程序。使用C#中的Masstransit/RabbitMQ將消息發送到特定的通道/路由密鑰

這是我想要的應用程序的工作方式:

Client sends a request for work (RPC). 

One of the worker roles accepts the work, generates a random id, and responds to the RPC with the new id. 
The worker will post its debug logs on a log channel with the id. 
The client will subscribe to this channel so users can see what's going on. 

的RPC工作正常,但我似乎無法弄清楚如何實施日誌傳送。

這是接受工作的代碼(簡化)

var bus = Bus.Factory.CreateUsingRabbitMq(sbc => 
{ 
    var host = sbc.Host(new Uri("rabbitmq://xxxxxx.nl"), h => 
    { 
     h.Username("xxx"); 
     h.Password("xxxx"); 
    }); 


    sbc.ReceiveEndpoint(host, "post_work_item", e => 
    { 
     e.Consumer<CreateWorkItemCommand>(); 
    }); 

    sbc.ReceiveEndpoint(host, "list_work_items", e => 
    { 
     e.Consumer<ListWorkItemsCommand>(); 
    }); 
}); 

CreateWorkItemCommand將創建線程,做的工作,等等。現在,我將如何實現日誌發送帶有Masstransit?我的想法是這樣的:

bus.Publish( 
    obj: WorkUpdate{ Message = "Hello world!" }, 
    channel: $"work/{work_id}" 
) 

而且客戶會做一些這樣的:

bus.ReceiveFromEvented($"work/{rpc.work_id}").OnMessage += { more_psuedo_code() } 

我似乎無法找出如何做到這一點。

任何人都可以幫我嗎?

謝謝!

回答

1

它看起來都像一個傳奇投票率。目前的投票率實施監督工作本身,我懷疑你真的可以訂閱該消息流。而且它還不是真的完成

你可以用saga來解決這個問題。一些外部觸發器(一個命令)將啓動第一個傳奇,它將使用請求/響應來啓動該進程,該進程將完成該工作並獲取其相關ID(作業ID)。長時間的工作可以使用相同的相關ID發佈進度報告,而傳奇將消耗它們,做它需要做的事情。

"work/{rpc.work_id}"將被替換爲關聯。

相關問題