0
我有一個問題,我不完全明白。 當我創建消息這樣它的工作原理:RabbitMq EasyNetQ使用Activator.CreateInstance創建消息
var message = new StartFakeJobCommand();
using (var publishChannel = ApplicationSingleton.Instance.RabbitBus.OpenPublishChannel())
{
publishChannel.Publish(message);
}
的消息被放入隊列中,我的聽衆可以使用它。 但是,當我使用創建消息Activator.CreateInstance像這樣,它不起作用。沒有任何內容發佈到隊列中。
var t = Type.GetType(string.Format("{0}.{1},{2}", job.CommandNamespace, job.Command, job.AssemblyName));
if (t == null)
throw new ArgumentException();
var message = Activator.CreateInstance(t);
using (var publishChannel = ApplicationSingleton.Instance.RabbitBus.OpenPublishChannel())
{
publishChannel.Publish(message);
}
在調試過程中,我可以清楚地看到使用這兩種方法創建了相同的類型。 任何想法爲什麼第二種方法不起作用?
這是我訂閱的消息:
bus.Subscribe<StartFakeJobCommand>("StartFakeJobCommand_ID", message => fakeJob.Handle(message));