Rebus 4.0 - 如何指定处理程序的顺序,尝试使用 "SpecifyOrderOfHandlers" 方法但给出编译时错误
Rebus 4.0 - How to specify order of handlers , tried with "SpecifyOrderOfHandlers" method but gives compile time error
你好 Rebus 粉丝,我们多年来一直在使用 Rebus 0.84 aka 1.0,现在 转向 4.0 版本 & 它似乎在实现和性能方面有了很大改进,但是执行处理程序命令时遇到一些问题。
之前版本的例子,我们曾经做过
public class RebusInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Configure.With(new WindsorContainerAdapter(container))
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
.SpecifyOrderOfHandlers(t => t.First<AuthenticationHandler>())
.Serialization(x => x.UseJsonSerializer())
.MessageOwnership(m => m.FromRebusConfigurationSection())
.Sagas(m => m.StoreInNDb())
.Subscriptions(m => m.StoreInNDb())
.Timeouts(m => m.StoreInMemory())
.Events(e =>
{
e.MessageSent += (advancedbus, destination, message) =>
{
var timeToBeReceived = ConfigurationManager.AppSettings["TimeToBeReceived"];
if (string.IsNullOrEmpty(timeToBeReceived))
timeToBeReceived = "00:00:30";
if (timeToBeReceived != "-1")
{
advancedbus.AttachHeader(message, Headers.TimeToBeReceived, timeToBeReceived);
advancedbus.AttachHeader(message, Headers.Express, "rebus-express");
}
};
})
.CreateBus()
.Start();
}
}
现在,如果我用 rebus 4.0 实现相同的功能,那么不知何故,在尝试 "SpecifyOrderOfHandlers" 时它会给出编译时错误,它不接受任何参数,那么我们如何实现处理程序的排序,下面是使用 rebus 4.0
实现
using Rebus.Config;
using Rebus.Persistence.InMem;
using Rebus.Handlers;
using Rebus.Messages;
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Configure.With(new CastleWindsorContainerAdapter(container))
.Options(o =>
{
o.SpecifyOrderOfHandlers(o => o.First<AuthenticationHandler>());
})
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmq(ConfigurationManager.AppSettings["InputQueue"]))
.Routing(r => r.TypeBasedRoutingFromAppConfig())
.Sagas(m => m.StoreInNDb())
.Subscriptions(m => m.StoreInNDb())
.Timeouts(m => m.StoreInMemory())
.Events(e =>
{
e.BeforeMessageSent += (bus, headers, message, context) =>
{
var timeToBeReceived = ConfigurationManager.AppSettings["TimeToBeReceived"];
if (string.IsNullOrEmpty(timeToBeReceived))
timeToBeReceived = "00:00:30";
if (timeToBeReceived != "-1")
{
headers.Add(Headers.TimeToBeReceived, timeToBeReceived);
headers.Add(Headers.Express, "rebus-express");
}
};
})
.Start();
}
请建议如何使用 rebus 4.0 实现处理程序排序,并让我知道上述实现 rebus 4.0 的方法是否正确或需要改进。
您只是让 SpecifyOrderOfHandlers
的调用有点太复杂了 – 这应该可以解决问题:
Configure.With(activator)
(...)
.Options(o =>
{
o.SpecifyOrderOfHandlers()
.First<AuthenticationHandler>();
})
.(...)
.Start();
如果不是很明显,那可能是因为 SpecifyOrderOfHandlers
在另一个命名空间中,所以如果您添加
using Rebus.Handlers.Reordering;
在文件顶部的某个地方,我敢打赌 IntelliSense 会引导你 :)
你好 Rebus 粉丝,我们多年来一直在使用 Rebus 0.84 aka 1.0,现在 转向 4.0 版本 & 它似乎在实现和性能方面有了很大改进,但是执行处理程序命令时遇到一些问题。
之前版本的例子,我们曾经做过
public class RebusInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Configure.With(new WindsorContainerAdapter(container))
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
.SpecifyOrderOfHandlers(t => t.First<AuthenticationHandler>())
.Serialization(x => x.UseJsonSerializer())
.MessageOwnership(m => m.FromRebusConfigurationSection())
.Sagas(m => m.StoreInNDb())
.Subscriptions(m => m.StoreInNDb())
.Timeouts(m => m.StoreInMemory())
.Events(e =>
{
e.MessageSent += (advancedbus, destination, message) =>
{
var timeToBeReceived = ConfigurationManager.AppSettings["TimeToBeReceived"];
if (string.IsNullOrEmpty(timeToBeReceived))
timeToBeReceived = "00:00:30";
if (timeToBeReceived != "-1")
{
advancedbus.AttachHeader(message, Headers.TimeToBeReceived, timeToBeReceived);
advancedbus.AttachHeader(message, Headers.Express, "rebus-express");
}
};
})
.CreateBus()
.Start();
}
}
现在,如果我用 rebus 4.0 实现相同的功能,那么不知何故,在尝试 "SpecifyOrderOfHandlers" 时它会给出编译时错误,它不接受任何参数,那么我们如何实现处理程序的排序,下面是使用 rebus 4.0
实现using Rebus.Config;
using Rebus.Persistence.InMem;
using Rebus.Handlers;
using Rebus.Messages;
public void Install(IWindsorContainer container, IConfigurationStore store)
{
Configure.With(new CastleWindsorContainerAdapter(container))
.Options(o =>
{
o.SpecifyOrderOfHandlers(o => o.First<AuthenticationHandler>());
})
.Logging(l => l.Log4Net())
.Transport(t => t.UseMsmq(ConfigurationManager.AppSettings["InputQueue"]))
.Routing(r => r.TypeBasedRoutingFromAppConfig())
.Sagas(m => m.StoreInNDb())
.Subscriptions(m => m.StoreInNDb())
.Timeouts(m => m.StoreInMemory())
.Events(e =>
{
e.BeforeMessageSent += (bus, headers, message, context) =>
{
var timeToBeReceived = ConfigurationManager.AppSettings["TimeToBeReceived"];
if (string.IsNullOrEmpty(timeToBeReceived))
timeToBeReceived = "00:00:30";
if (timeToBeReceived != "-1")
{
headers.Add(Headers.TimeToBeReceived, timeToBeReceived);
headers.Add(Headers.Express, "rebus-express");
}
};
})
.Start();
}
请建议如何使用 rebus 4.0 实现处理程序排序,并让我知道上述实现 rebus 4.0 的方法是否正确或需要改进。
您只是让 SpecifyOrderOfHandlers
的调用有点太复杂了 – 这应该可以解决问题:
Configure.With(activator)
(...)
.Options(o =>
{
o.SpecifyOrderOfHandlers()
.First<AuthenticationHandler>();
})
.(...)
.Start();
如果不是很明显,那可能是因为 SpecifyOrderOfHandlers
在另一个命名空间中,所以如果您添加
using Rebus.Handlers.Reordering;
在文件顶部的某个地方,我敢打赌 IntelliSense 会引导你 :)