有没有可能通过IJobActivator内部的服务总线触发器在web作业中获取底层BrokeredMessage?这在多租户场景中非常有用。
我正在使用一个带有Unity的自定义IJobActivator来实例化我的作业。在我的UnityJobActivator类中,我希望能够查看底层的BrokeredMessage并从中提取一些自定义属性,比如我的所有消息都有的"Tenant“。这将允许我在作业类执行之前将适当的数据库连接或配置对象注入到作业类中。
下面是一个示例,其中我希望将ITenantConfiguration注入到作业中,但必须基于BrokeredMessage自定义属性。如果我能从我的UnityJobActivator中访问BrokeredMessage,我就能做到这一点。
public class CustomJob
{
private const string Subscription = "subscription";
private const string Topic = "topic";
private ITenantConfiguration config;
public CustomJob(ITenantConfiguration config)
{
// This configuration depends on the Tenant property of the BrokeredMessage
this.config = config;
}
public void Handle([ServiceBusTrigger(Topic, Subscription)] MyMessage myMessage)
{
// Do something with myMessage and the appropriate configuration
}
}发布于 2015-07-23 09:39:46
可以,绑定BrokeredMessage而不是MyMessage:
public void Handle([ServiceBusTrigger(Topic, Subscription)] BrokeredMessage myMessage)
{ ... }https://stackoverflow.com/questions/31410896
复制相似问题